
记忆化搜索
文章平均质量分 90
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Form Largest Integer With Digits That Add up to Target
Given an array of integerscostand an integertarget. Return themaximuminteger you can paintunder the following rules:The cost of painting adigit (i+1) is given bycost[i](0 indexed). The total cost used mustbe equal totarget. Integer does not ...原创 2020-09-21 02:39:21 · 275 阅读 · 0 评论 -
Number of Dice Rolls With Target Sum
You haveddice, and each die hasffaces numbered1, 2, ..., f.Return the number of possible ways (out offdtotal ways)modulo10^9 + 7to roll the dice so the sum of the face up numbers equalsta...原创 2020-04-28 09:41:33 · 268 阅读 · 0 评论 -
Minimum Cost to Cut a Stick
Given a wooden stick of lengthnunits. The stick is labelled from0ton. For example, a stick of length6is labelled as follows:Given an integer arraycutswherecuts[i]denotes a position you should perform a cut at.You should perform the cuts in...原创 2020-08-24 13:11:38 · 408 阅读 · 0 评论 -
Stone Game V
There are several stonesarranged in a row, and each stone has an associatedvalue which is an integer given in the arraystoneValue.In each round of the game, Alice divides the row intotwo non-empty rows(i.e. left row and right row), then Bob calculat...原创 2020-08-23 13:20:07 · 308 阅读 · 0 评论 -
Minimum Number of Days to Eat N Oranges
There arenoranges in the kitchen and you decided to eat some of these oranges every day as follows:Eat one orange. If the number of remaining oranges (n) is divisible by 2 then you can eat n/2 oranges. If the number of remaining oranges (n) is divis...原创 2020-08-16 13:34:40 · 252 阅读 · 0 评论 -
记忆化搜索总结
DFS + Memo就是DP,注意cache存的物理意义,因为DFS是top down的,那么都是走到base case了,然后返回,那么存的结果就是从base case来的结果,那么就是存dp[0][0], dp[0][1] .. 一直到dp[n][target]. 最后返回的就是dp[n][ target],还有个tricky的地方就是表示是否有值和是否访问过,解决方法就是存-1,代表没有访问...原创 2020-04-28 09:39:52 · 1387 阅读 · 0 评论 -
Minimum Insertion Steps to Make a String Palindrome
Given a strings. In one step you can insert any character at any index of the string.Returnthe minimum number of stepsto makespalindrome.APalindrome Stringis one that reads the same backward as well as forward.Example 1:Input: s = "zzazz"O...原创 2020-06-29 04:00:24 · 507 阅读 · 0 评论 -
Minimum Distance to Type a Word Using Two Fingers
You have a keyboard layout as shown above in the XY plane, where each English uppercase letter is located at some coordinate, for example, the letterAis located at coordinate(0,0), the letterBis located at coordinate(0,1), the letterPis located a...原创 2020-06-25 07:12:47 · 268 阅读 · 0 评论 -
Maximum Points You Can Obtain from Cards
There are several cardsarranged in a row, and each card has an associated number of pointsThe points are given in the integer arraycardPoints.In one step, you can take one card from the beginning or from the end of the row. You have to take exactlyk...原创 2020-06-19 11:32:17 · 489 阅读 · 0 评论 -
Guess Number Higher or Lower II
We are playing the Guess Game. The game is as follows:I pick a number from1ton. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number I picked is higher or lower.However, when you guess a particular n...原创 2020-06-17 02:06:19 · 212 阅读 · 0 评论 -
Cherry Pickup II
Given arows x colsmatrixgridrepresenting a field of cherries.Each cell ingridrepresents the number of cherries that you can collect.You have tworobots that can collect cherries for you, Robot #1 is located at the top-left corner (0,0) , and Robot...原创 2020-06-16 14:12:07 · 498 阅读 · 0 评论 -
Kth Ancestor of a Tree Node
You are given a tree withnnodes numbered from0ton-1in the form of a parent array whereparent[i]is the parent of nodei. The root of the tree is node0.Implement the functiongetKthAncestor(int node, int k)to return thek-th ancestor of the given...原创 2020-06-14 12:40:07 · 400 阅读 · 0 评论 -
Number of Ways to Stay in the Same Place After Some Steps
You have a pointer at index0in an array of sizearrLen. At each step, you can move 1 position to the left, 1 position to the rightin the array or stay in the same place (The pointer should not be placed outside the array at any time).Given two intege...原创 2020-06-14 03:51:11 · 306 阅读 · 0 评论 -
Number of Ways to Paint N × 3 Grid
You have agridof sizen x 3and you want to paint each cell of the grid with exactlyone of the three colours:Red,YelloworGreenwhile making sure that no two adjacent cells havethe same colour (i.e no two cells that share vertical or horizontal side...原创 2020-06-12 05:14:36 · 257 阅读 · 0 评论 -
Burst Balloons
Givennballoons, indexed from0ton-1. Each balloon is painted with a number on it represented by arraynums. You are asked to burst all the balloons. If the you burst ballooniyou will getnums[le...原创 2019-12-08 08:43:00 · 243 阅读 · 0 评论 -
Stone Game II
Alexand Lee continue theirgames with piles of stones. There are a number ofpilesarranged in a row, and each pile has a positive integer number of stonespiles[i]. The objective of the game is to end with the moststones.Alex and Lee take turns, wi...原创 2020-06-11 07:47:35 · 252 阅读 · 0 评论 -
Cherry Pickup
In a N x Ngridrepresenting a field of cherries, each cell is one of three possible integers.0 means the cell is empty, so you can pass through; 1 means the cell contains a cherry, that you can pi...原创 2020-03-28 10:02:40 · 330 阅读 · 0 评论 -
Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5...原创 2014-12-09 12:53:16 · 578 阅读 · 0 评论 -
Wildcard Matching
Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover ...原创 2014-12-18 09:28:06 · 576 阅读 · 0 评论 -
Regular Expression Matching
Implement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input s...原创 2014-12-16 15:14:40 · 532 阅读 · 0 评论