leetcode552. Student Attendance Record II

xiaoxiao2021-02-27  207

leetcode  552. Student Attendance Record II

又一题动态规划

public class Solution { public int checkRecord(int n) { final int MOD = 1000000007; int[][][] f = new int[n+1][2][3]; // at most 1 A, at most 2 L f[0] = new int[][]{{1, 1, 1}, {1, 1, 1}}; for(int i=1;i<=n;i++){ for(int j=0;j<=1;j++){ for(int k=0;k<=2;k++){ int val = f[i-1][j][2]; // ..p if(j>0) val = (val + f[i-1][j-1][2])%MOD; // ..A if(k>0) val = (val + f[i-1][j][k-1])%MOD; // ..L f[i][j][k] = val; // } } } return f[n][1][2]; } }

转载请注明原文地址: https://www.6miu.com/read-9218.html

最新回复(0)