Description
In the Spring Festival day, Xiao Ming Jamie in the laboratory brush questions. Brush with Xiao Ming feel tired, invited Xiao Ming together to see the Spring Festival Gala. Xiao Ming think xiaoming is bored, don't want to Li Xiaoming, but xiaoming very will grind lip, Xiao Ming can not withstand Xiao Ming's hu Mouth 蛮缠, so and Xiao Ming together to see the Spring Festival Gala.
Xiao Ming immediately feel the double son cool Ah! But a look, "Wocao", "the most dazzling little Apple", Xiao Ming immediately feel very sad. "Even the little apples are in the company ... Whining.... Xiao Ming saw Xiao Ming cry, want to comfort him, but how to comfort it!
Xiao Ming fell into a meditation, suddenly, Xiao Ming a flash, want to borrow the name, let Xiao Ming happy up. So Xiao Ming said to Xiao Ming, since the small apples are companion, then we two bachelor away from the list is not far away! Crackling, Xiao Ming said to Xiao Ming or we also come to let The Bachelor have a companion! Exactly, in our school's school game, we will be a bachelor in the name of a problem. Xiao Ming heard to the question, and immediately got the strength ... They think "11" is the symbol of singles paired, so, Xiao Ming Jamie want to ask you, for a length of 01 strings of N, in the end how many strings are containing "11" substring? Smart you, I believe you have the idea of how AC.
For example, a length of 2 has "11" a qualifying 01 strings;
A length of 3 has "111", "110", "011" three strings that meet the conditions;
Lengths of 4 have "1111", "1101", "1100", "0011", "1011", "0111", "0110", "1110" eight qualifying strings.
Input
There is a T set of data input. (t<=1000);
Only one row per set of data, a positive integer n (1<=n<=10^6)
Output
For each set of data output a row of results, 1000000007 modulo.
Sample Input3145Sample Output0819The main idea: to get at least two of the sum of all the sequence together, in turn to find two one does not depend on the more convenient, you can derive the dynamic equation: dp[1][0] = dp[1][1] = 1;dp[i][0] = dp[i-1][1] + dp[i-1][0];DP [i][1 ] = Dp[i-1][0];(seen as a direction)
#include <cstring>#include<cstdio>#include<iostream>using namespacestd;Const intMAX =1000010;Const intMOD = 1e9+7;intdp[max][2];intA[max];intMain () {a[1] =2; Memset (DP,0,sizeof(DP)); dp[1][1] = dp[1][0] =1; for(inti =2; i < MAX; i++) {dp[i][0] = dp[i-1][1] + dp[i-1][0]; if(dp[i][0] >MOD) dp[i][0] -=MOD; dp[i][1] = dp[i-1][0]; A[i]= a[i-1]*2; } intT,n; CIN>>T; while(t--) {scanf ("%d",&N); intAns = a[n]-(dp[n][1]+dp[n][0]); Ans%=MOD; cout<< ans <<Endl; } return 0;}
View Code
01 Strings of crazy singles, too.