摘要: 分析:将木棍的两个端点(0和n)加到cost数组中,dp[i][j]表示把这段木棍的第i到j个点完成切割的最小成本,i和j都是cost数组的下标。 状态计算: 最后的合并位置是k dp[i][j] = min(dp[i, k] + dp[k, j] + cost) class Solution { 阅读全文
posted @ 2020-08-10 19:48 Sexyomaru 阅读(454) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int maxNonOverlapping(int[] nums, int target) { int n = nums.length; int[] dp = new int[n+1]; // nums前i个数的最大满足条件子数组数目 Map<Inte 阅读全文
posted @ 2020-08-10 19:32 Sexyomaru 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 1540. K 次操作转变字符串 class Solution { public boolean canConvertString(String s, String t, int k) { if(s.length() != t.length()) return false; int n = s.le 阅读全文
posted @ 2020-08-10 19:29 Sexyomaru 阅读(120) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int countBinarySubstrings(String s) { int n = s.length(); int res = 0; int pre = 0, cur = 1; for(int i = 1; i < n; i++) { if(s 阅读全文
posted @ 2020-08-10 10:48 Sexyomaru 阅读(97) 评论(0) 推荐(0) 编辑