# Student Attendance Record II

Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after mod 109 + 7.

A student attendance record is a string that only contains the following three characters:

1. 'A' : Absent.
2. 'L' : Late.
3. 'P' : Present.

A record is regarded as rewardable if it doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).

Example 1:

Input: n = 2
Output: 8
Explanation:
There are 8 records with length 2 will be regarded as rewardable:
"PP" , "AP", "PA", "LP", "PL", "AL", "LA", "LL"
Only "AA" won't be regarded as rewardable owing to more than one absent times.


Note: The value of n won't exceed 100,000.

dp[i][0]:此前未旷课，且最后一天未迟到

dp[i][1]:此前未旷课，且最后一天迟到

dp[i][2]:此前未旷课，且最后两天迟到

dp[i][3]:此前旷课一次，且最后一天未迟到

dp[i][4]:此前旷课一次，且最后一天迟到

dp[i][5]:此前旷课一次，且最后两天迟到

dp[i+1][0] = dp[i][0]P + dp[i][1]P + dp[i][2]P + dp[i][3]A + dp[i][4]A + dp[i][5]A

dp[i+1][1] = dp[i][0]L

dp[i+1][2] = dp[i][1]L

dp[i+1][3] = dp[i][3]P + dp[i][4]P + dp[i][5]P

dp[i+1][4] = dp[i][3]L

dp[i+1][5] = dp[i][4]L

    public int checkRecord(int n) {
long[] cur = new long[]{1, 0, 0, 1, 1, 0}, next;
if(n == 0)
return 0;
for(int i = 1; i < n; i++){
next = new long[6];
next[0] = cur[0] + cur[1] + cur[2] + cur[3] + cur[4] + cur[5];
next[1] = cur[0];
next[2] = cur[1];
next[3] = cur[3] + cur[4] + cur[5];
next[4] = cur[3];
next[5] = cur[4];
for(int j = 0; j < 6; j++)
next[j] %= 1000000007;
cur = next;
}
long res = 0;
for(long num : cur)
res += num;
res %= 1000000007;
return (int)res;
}