1687. Permutation
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
Permutation plays a very important role in Combinatorics.
For example, 1 2 3 4 5 and 1 3 5 4 2 are both 5-permutations.
As everyone's known, the number of n-permutations is n!.
According to their magnitude relatives, if we insert the symbols '<' or '>' between every pairs of consecutive numbers of a permutation, we can get the permutation with symbols.
For example, 1 2 3 4 5 can be changed to 1<2<3<4<5,
1 3 5 4 2 can be changed to 1<3<5>4>2.
Now it's your task to calculate the number of n-permutations with k '<' symbols.
Maybe you don't like large numbers, so you should just give the result mod 2007.
Input
Input may contain multiple test cases.
Each test case is a line contains two integers n and k.0<n<=100 and 0<=k<=100.
The input will terminated by EOF.
Output
The nonnegative integer result mod 2007 on a line.
Sample Input
5 2
Sample Output
66
何叶红同学的解答非常好,大家鼓掌
点击打开链接
代码如下:
#include <iostream> #include <cstring> #include <stdio.h> // for scanf and EOF using namespace std; int dp[105][105]; void init() { dp[0][0]=1; for (int i = 1; i < 105; ++i) { /* code */ dp[i][0]=1; for (int j=1;j<i-1;j++) { /* code */ dp[i][j]=(dp[i-1][j]*(j+1)%2007+dp[i-1][j-1]*(i-j)%2007)%2007; } dp[i][i-1]=1; } } int main() { init(); int a,b; while(scanf("%d%d",&a,&b)!=EOF) { cout<<dp[a][b]<<endl; } // system("pause"); }