博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
552. Student Attendance Record II
阅读量:5161 次
发布时间:2019-06-13

本文共 1285 字,大约阅读时间需要 4 分钟。

Problem refer: https://leetcode.com/problems/student-attendance-record-ii/description

// My solution:// A good mathmatical derivation problem.// But it makes me confused with the word: "more than two continuous 'L' (late)".// And finally find it actually represents "LLL".// The last solution refers to the discuss: // https://discuss.leetcode.com/topic/86696/share-my-o-n-c-dp-solution-with-thinking-process-and-explanationclass Solution {public:    static const int N = 100000 + 1;    static const int MOD = 1000000000 + 7;    int P[N],L[N],A[N];    int ans[N];        int calc(int n) {        if (ans[n]) return ans[n];        calc(n-1);                P[n] = (P[n-1] + A[n-1])%MOD + L[n-1];        P[n] %= MOD;                L[n] = ((P[n-1] + A[n-1])%MOD + A[n-2])%MOD + P[n-2];        L[n] %= MOD;        A[n] = (A[n-1] + A[n-2])%MOD + A[n-3];        A[n] %= MOD;        ans[n] = (P[n] + L[n])%MOD + A[n];        ans[n]%=MOD;        return ans[n];    }    int checkRecord(int n) {        memset(ans, 0, sizeof ans);        P[1]=L[1]=A[1]=1;        ans[1] = 3;            P[2] = L[2] = 3;        A[2] = 2;        ans[2] = 8;            P[3] = 8;        L[3] = 7;        A[3] = 4;        ans[3] = 19;        return calc(n);    }};

 

转载于:https://www.cnblogs.com/kkrisen/p/7897923.html

你可能感兴趣的文章
Javascript中eval解析的json的几种用法
查看>>
Dashbroad 展现数据
查看>>
Jedis路由key的算法剥离
查看>>
Codeforces Round #485 (Div. 2)
查看>>
记一次博客被群压的经历
查看>>
Java String codePoint相关api
查看>>
bzoj4447 SCOI2015 小凸解密码 password
查看>>
解析Ceph: RBDCache 背后的世界
查看>>
qt安装遇到的错误
查看>>
Linux下which、whereis、locate、find 区别
查看>>
h.264加权预测
查看>>
as4 通过yum自动升级实现
查看>>
mimtproxy的使用(windows)
查看>>
学习springMVC实例1——配置和跳转到HelloWorld
查看>>
注解@Slf4j
查看>>
92:Reverse Linked List II翻转链表【链表】
查看>>
JDBC 获取被插入数据的主键ID值
查看>>
new Date()时间对象
查看>>
Tomcat配置SSL连接
查看>>
最短路
查看>>