Problem 660
Student Attendance Record II
Hard · 30 pts · Dynamic Programming
Problem
An attendance record of length N is a string of the letters A (absent), L (late) and P (present). A record earns an award if it has fewer than 2 A's in total and never has 3 or more L's in a row. Count the award-eligible records of length N, modulo 1000000007. Track the number of valid records by state: how many A's they contain (0 or 1) and how many L's they end with (0, 1 or 2), and extend each state by P, A or L. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).
Input
A single integer N.
Output
Print the number of eligible records modulo 1000000007.
Constraints
1 <= N <= 100000
Example input
2
Example output
8
Explanation
For N = 2 all 9 two-letter records are eligible except AA, which has two absences. So the answer is 8.