Problem description
We call a number interesting when and only if:
1. Its numbers contain only 0, 1, 2, 3, and these four numbers appear at least once.
2. All 0 appear before all 1, and all 2 appear before all 3.
3. The maximum number of digits is not 0.
Therefore, the smallest interesting number that conforms to our definition is 2013. In addition, the 4-bit interesting number also has two: 2031 and 2301.
Please calculate the number of interesting numbers that happen to have n bits. Because the answer can be very large, only the remainder of the output answer divided by 1000000007 is required.
Input format
The input has only one row, including exactly a positive integer n (4≤n≤1000).
Output format
The output has only one row, including the number of interesting numbers in the exact n-bit integer divided by the remainder of 1000000007.
Sample input
4
Sample output
3
Dynamic Programming Solution:
import java.util.*;p ublic class main { public Static void main (String[] args) { new main (). Run () ;} Public void run () { Scanner fin = new Scanner (system.in); int n = fin.nextint (); &NBSP;&NBSP;&NBSP;LONG[]&NBSP;COUNT&NBSP;=&NBSP;NEW&NBSP;LONG[8];&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;COUNT[6] = 0; count[7] = 1; long mod = 1000000007; for (int i = 2; i <= n; ++i) { long[] newCount = new long[8]; newcount[0] = (Count[0] * 2 + count[1] + count[3]) % mod; newCount[1] = (count[1] * 2 + count[2] +&NBSP;COUNT[5]) % mod; newCount[2] = (Count[2] + count[6]) % mod; newCount[3] = (count[3] * 2 + count[4] + count[5]) % mod; newcount[4] = (count[4] + COUNT[7]) % mod; newCount[5] = (Count[5] * 2 + count[6] + count[7]) % mod; newCount[6] = 0; newcount[7] = 1; count = newcount; } system.out.println (count[0]); }}
This article is from a "stroll," blog, please be sure to keep this source http://macxiao.blog.51cto.com/9606147/1587773
Interesting number (dynamic planning)