Permutation counting
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1487 Accepted Submission (s): 754
Problem Descriptiongiven a permutation A1, A2, ... an of {1, 2, ..., N}, we define its e-value as the amount of elements where Ai > I. For example, the e-value of permutation {1, 3, 2, 4} are 1, while the e-value of {4, 3, 2, 1} is 2. Requested to find how many permutations of {1, 2, ..., N} whose e-value is exactly K. Inputthere is several test CA SES, and one line for each case, which contains-integers, N and K. (1 <= N <=, 0 <= k <= N). Outputoutput one line for each case. For the answer is quite huge, you need to output the answer module 1,000,000,007. Sample INPUT3 1 Sample Output14
HintThere is only one permutation with E-value 0: {}, and there am four permutations with E-value 1: {1,3,2}, {2,1,3}, { 3,1,2}, {3,2,1} Source2010 Asia regional Harbin test instructions: For any sort of n permutation a, define its e value as the number of numbers in the sequence that satisfy a[i]>i. Given N and K (k<=n<=1000), the number of e values in the permutation of N is K. DP[I][J] Indicates the number of the number of the first I in the order of the E value of J, so when the number of i+1 inserted, if placed in the first i+1 or meet the condition J position, J is unchanged, and the rest of the i-j position of the number of the exchange of J +1. So dp[i+1][j] = Dp[i+1][j] + (j + 1) * Dp[i][j];DP [i+1][j+1] = dp[i+1][j+1] + (I-J) * DP[I][J];
/*id:linkarftcprog:3664.cpplang:c++*/#include<map>#include<Set>#include<cmath>#include<stack>#include<queue>#include<vector>#include<cstdio>#include<string>#include<utility>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;#defineEPS 1e-8#defineRandin Srand ((unsigned int) time (NULL))#defineInput freopen ("Input.txt", "R", stdin)#defineDebug (s) cout << "s =" << s << endl;#defineOutstars cout << "*************" << Endl;Const DoublePI = ACOs (-1.0);Const DoubleE = exp (1.0);Const intINF =0x3f3f3f3f;Const intINF =0x7fffffff; typedefLong Longll;Const intMAXN =1010;Const intMOD =1000000007; ll DP[MAXN][MAXN];intN, K;voidinit () {dp[1][0] =1; dp[1][1] =0; for(inti =1; I <= +; i + +) { for(intj =0; J <= +; J + +) {Dp[i+1][J] = (dp[i+1][J]% MOD + (j +1) * Dp[i][j]% MOD)%MOD; Dp[i+1][j+1] = (dp[i+1][j+1]% mod + (i-j) * Dp[i][j]% MoD)%MOD; } }}intMain () {init (); while(~SCANF ("%d%d", &n, &k)) {printf ("%d\n", Dp[n][k]); } return 0;}
HDU3664 Permutation counting