csuoj 1968 递推
2017-07-24 08:15
405 查看
Description
Given a positive integer, N, a permutation of order N is a one-to-one (and thus onto) function from the set of integers from 1 to N to itself. If p is such a function, we represent the function by a list of its values:[ p(1) p(2) … p(N) ]
For example,
[5 6 2 4 7 1 3]represents the function from
{ 1 … 7 }to itself which takes 1 to 5, 2 to 6, … , 7 to 3.
For any permutation p, a descent of p is an integer k for which
p(k) > p(k+1). For example, the permutation
[5 6 2 4 7 1 3]has a descent at 2
(6 > 2)and 5
(7 > 1).
For permutation p,
des(p)is the number of descents in p. For example,
des([5 6 2 4 7 1 3]) = 2. The identity permutation is the only permutation with
des(p) = 0. The reversing permutation with
p(k) = N+1-kis the only permutation with
des(p) = N-1.
The permutation descent count (PDC) for given order N and value v is the number of permutations p of order N with
des(p) = v. For example:
PDC(3, 0) = 1 { [ 1 2 3 ] }
PDC(3, 1) = 4 { [ 1 3 2 ], [ 2 1 3 ], [ 2 3 1 ], 3 1 2 ] }
PDC(3, 2) = 1 { [ 3 2 1 ] }`
Write a program to compute the PDC for inputs N and v. To avoid having to deal with very large numbers, your answer (and your intermediate calculations) will be computed modulo
1001113.
Input
The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set should be processed identically and independently.Each data set consists of a single line of input. It contains the data set number, K, followed by the integer order, N (2 ≤ N ≤ 100), followed by an integer value, v (0 ≤ v ≤ N-1).
Output
For each data set there is a single line of output. The single output line consists of the data set number, K, followed by a single space followed by the PDC of N and v modulo 1001113 as a decimal integer.Sample Input
4 1 3 1 2 5 2 3 8 3 4 99 50
Sample Output
1 4 2 66 3 15619 4 325091
Hint
Source
2017湖南多校第十三场题意:
要你求1~n的全排列中逆序数为 v 的个数
题解:
递推打表即可
用dp[ i ][ j ]表示 1~i 的全排列逆序数为 j 的个数
这个数来源于两个方向:dp[ i-1 ][ j-1 ] 和 dp[ i-1 ][ j ]
仔细考虑,分析已经有的逆序数对和不是逆序数对的地方插入一个数,以及头和尾考虑一下即可
代码就很简单了
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define mod 1001113 int dp[200][200]; void init() { for(int i=0;i<=100;i++) dp[i][0]=1; for(int i=1;i<=100;i++) for(int j=1;j<i;j++) dp[i][j]=(dp[i-1][j-1]*(i-j)%mod+dp[i-1][j]*(j+1)%mod)%mod; } int main() { int T; init(); int t,n,k; //freopen("in.txt","r",stdin); scanf("%d",&T); while(T--) { scanf("%d%d%d",&t,&n,&k); printf("%d %d\n",t,dp [k]); } return 0; }
相关文章推荐
- CSUOJ 1005 Binary Search Tree analog
- CSUOJ Water Drinking
- CSUOJ 赌神的战斗
- 【杭电oj】5620 - KK's Steel(递推)
- 杭电OJ(HDOJ)2041题:超级阶梯(规律递推,Fibonacci)
- CSUOJ—1803
- csuoj 1334: 好老师
- CSUOJ1206--Card game
- UOJ #244. 【UER #7】短路 贪心+递推
- CSUOJ 1112 机器人的指令
- csu oj K swap operation 模拟
- 【杭电oj】2045 - 不容易系列之(3)—— LELE的RPG难题(递推)
- Stock Wave+csuoj+简单dp
- csuoj-1718- And Then There Was 5
- CSUOJ 1150-食用油
- 【杭电-oj】-2044-一只小蜜蜂...(递推)
- CSUOJ 1858 Biorhythms 中国剩余定理
- CSUOJ 1531 Jewelry Exhibition
- OJ2755神器的口袋 普通递归+递推+递推滚动数组
- CSUOJ 1808 地铁(用map储存DP数组的DP)