Big Move accepts:207 submissions:713
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Problem Description
Recently, b factory organized a big move, everyone to follow the instructions to change to the designated seat. The indicated content is that the person sitting on position II will move to the position JJ. Now the B factory has the NN individual, one to the nn position. After the move is also one by one corresponding, change only the rank.
After the first move, the degree of bear due to negligence, but also asked you to follow the original instructions for a move. So, the wit of it thought: again according to the instructions to move home once again can restore the first time the appearance of the move. As a result, plant B has carried out an unprecedented three consecutive moves.
While we all know that the "wit" of a bear is often worrying, it is inconceivable that this is a real thing. The result of the third move is exactly the same as the result of the first time.
So, how many kinds of instructions are going to make this happen? If at least one of the two instructions has a different target location, the two instructions are considered to be not the same.
Input
The first line is an integer TT, which represents the T-group data.
Each set of data contains an integer n (1 \leq n \leq 1) n (1≤n≤1000000).
Output
For each set of data, output one line of case #i: Then output the result, modulo 10000000071000000007.
Sample Input
Copy
2
1
3
Sample Output
Case #1:
1
Case #2:
4
The subject is a DP topic, first of all to push the value of the first few, when N=1, 1 and 1 itself exchange have a method, when n=2, (1 and 2 Exchange, 2 and 1 Exchange), (1 and 1 Exchange, 2 and 2 Exchange), when n=3 (1 and 1 Exchange, 2 and 3 Exchange, 3 and 2 Exchange), (1 and 1 exchange, 2 and 2 swaps, 3 and 3 Swaps), (1 and 3 swaps, 3 and 1 swaps, 2 and 2 swaps), (1 and 2 swaps, 2 and 1 swaps, 3 and 3 swaps). n equals 4 o'clock there are 10 ways to do this, and now look at the law of the first few numbers to get the equation of state transition.
dp[i]=(dp[i-1]+((i-1)%MOD)*(dp[i-2]%MOD))%MOD;
Here is the AC code:
#include <cstdio>#include <algorithm>#define MOD 1000000007using namespace STD;Long Long intdp[1000005];intMain () {dp[1]=1; dp[2]=2; for(Long Long intI=3;i<1000003; i++) {dp[i]= (dp[i-1]+ ((I-1)%mod) * (dp[i-2]%MOD))%mod; }intT,icase=0;Long LongNscanf("%d", &t); while(t--) {icase++;scanf("%i64d", &n);printf("Case #%d:\n%i64d\n", Icase,dp[n]%mod); }return 0;}
HDU 201,500-degree star Qualifying tournament-big move