
动态规划-基础DP
garett.
这个作者很懒,什么都没留下…
展开
-
「LeetCode639」简单DP
class Solution { public static final long MOD=1000000007; public int numDecodings(String str) { char[] s=str.toCharArray(); int n=s.length; long[] dp=new long[n]; if(s[0]=='0') return 0; dp[0]=(.原创 2021-09-27 10:15:41 · 95 阅读 · 0 评论 -
「LeetCode」学生出勤记录 II 动态规划|矩阵快速幂
解法1: dp[ i ][ j ][ k ] 表示枚举到第 i 天时恰好有 j 次迟到 k 次缺勤时的方案数,时间复杂度 O(n)class Solution: def checkRecord(self, n: int) -> int: mod=10**9+7 dp=[[[0]*2 for j in range(3)] for i in range(n+1)] dp[0][0][0]=1 for i in range(1.原创 2021-08-18 23:49:53 · 232 阅读 · 0 评论 -
[LeetCode] 第165场周赛题解
第一题:按题意模拟。public class Solution { public boolean check(int[][] map,int val) { for(int i=0;i<3;i++) { if(map[i][0]==val&&map[i][1]==val&&map[i][2]==val) return true; ...原创 2019-12-10 08:17:49 · 149 阅读 · 0 评论 -
[LeetCode] 第158场周赛题解
第一题:public class Solution { public int balancedStringSplit(String s) { int ans=0; int[] buf=new int[s.length()]; buf[0]=s.charAt(0)=='R'?-1:1; for(int i=1;i<s...原创 2019-11-27 20:10:16 · 164 阅读 · 0 评论 -
[LeetCode] 第160场周赛题解
第一题:因为该函数具有严格的单调性,所以可以二分,即枚举x二分y,但数据范围过小没啥必要。public class Solution { public List<List<Integer>> findSolution(CustomFunction func, int z) { List<List<Integer>> ans=new A...原创 2019-11-27 10:51:39 · 356 阅读 · 0 评论