随笔分类 - DP
摘要:class Solution { public int rob(int[] nums) { if(nums.length==0) return 0; if(nums.length==1) return nums[0]; return Math.max(rob1(nums, 0, nums.le...
阅读全文
摘要:class Solution { public int maxProfit(int k, int[] prices) { if(k>=prices.length/2) { int maxProfit=0; for(int i=1;iprices[i-1]?prices[i]-prices[i-1]:0; ...
阅读全文
摘要:class Solution { public int calculateMinimumHP(int[][] dungeon) { if(dungeon.length==0||dungeon[0].length==0) return 0; int M=dungeon.length; int N=dungeon[0]....
阅读全文
摘要:class Solution { public boolean wordBreak(String s, List wordDict) { boolean[] dp=new boolean[s.length()+1]; dp[0]=true; for(int i=0;i=0&&w.equals(s.substring(i+1-w.length...
阅读全文
摘要:class Solution { public int minCut(String s) { int[] dp=new int[s.length()+1]; for(int i=0;i=0&&i+len=0&&i+len<s.length()&&s.charAt(i-1-len)==s.charAt(i+len);len++) ...
阅读全文
摘要:压缩
阅读全文
摘要:class Solution { public int minimumTotal(List> triangle) { int[] dp=new int[triangle.size()]; for(int i=triangle.size()-1;i>=0;i--) for(int j=0;j<=i;j++) ...
阅读全文
摘要:class Solution { public int numDistinct(String s, String t) { int[][] dp=new int[t.length()+1][s.length()+1]; for(int i=0;i<=t.length();i++) for(int j=i;j<=s.length();...
阅读全文
摘要:class Solution { public boolean isInterleave(String s1, String s2, String s3) { if(s1.length()+s2.length()!=s3.length()) return false; boolean [][] dp=new boolean[s1.l...
阅读全文
摘要:public class Solution { public int numTrees(int n) { int[] dp=new int[n+1]; dp[0]=1; dp[1]=1; for(int i=2;i<=n;i++) for(int j=1;j<=i;j++) ...
阅读全文
摘要:public class Solution { public int numDecodings(String s) { if(s.length()==0) return 0; int[] dp=new int[s.length()+1]; dp[0]=1; for(int i=0;i'0'&&s.ch...
阅读全文
摘要:class Solution { public int minDistance(String word1, String word2) { int[][] dp=new int[word1.length()+1][word2.length()+1]; for(int i=0;i<=word1.length();i++) dp[i][...
阅读全文
摘要:class Solution { public int minPathSum(int[][] grid) { for(int i=0;i0&&j>0) grid[i][j]+=Math.min(grid[i-1][j],grid[i][j-1]); else if(j>0) ...
阅读全文
摘要:class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { for(int i=0;i=0?1:0; for(int i=0;i=0) obstacleGrid[i][j]+=(i>0&&obstacleGrid[i-1][...
阅读全文
摘要:class Solution { public int uniquePaths(int m, int n) { int[][] dp=new int[m][n]; dp[0][0]=1; for(int i=0;i0?dp[i-1][j]:0)+(j>0?dp[i][j-1]:0); return dp[m-1][n-1];...
阅读全文
摘要:class Solution { public boolean isMatch(String s, String p) { boolean[][] dp=new boolean[p.length()+1][s.length()+1]; dp[0][0]=true; for(int i=1;i0&&(p.charAt(i-1)==s.char...
阅读全文
摘要:Recursive DP
阅读全文
摘要:Time Limit: 3000MSMemory Limit: 65536KTotal Submissions: 26714Accepted: 8915DescriptionA palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right...
阅读全文
摘要:Time Limit: 1000MSMemory Limit: 10000KTotal Submissions: 8125Accepted: 4497DescriptionIt is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simp...
阅读全文
摘要:Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 5823Accepted: 3802DescriptionThe cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though...
阅读全文

浙公网安备 33010602011771号