# permutation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 126    Accepted Submission(s): 72

Problem 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 sumbols "<" or ">"between every pairs of consecutive numbers of a permutations,we can get the permutations 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 yout task to calculate the number of n-permutations with k"<"symbol. Maybe you don't like large numbers ,so you should just geve the result mod 2009.

Input
Input may contai 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 nonegative integer result mod 2007 on a line.

Sample Input
5 2

Sample Output
66

the number of n-permutations with k"<"symbol is F[n][k]（n-全排列中有k个<符号的排列一共有F[n][k]个）.

/*the number of n-permutations with k"<"symbol is F[n][k]
find the turning
F[i][0]=1,F[i][i-1]=1,i>j,i(n),j(k) 0<i<=100,0<=k<=100
以1 3 2 5 4为例，如果我们要插入6,如何办，分<和>分析可知
F[n+1][k] = F[n][k]*(k+1)+F[n][k-1]*(n-k+1)
F[1][0]=F[2][0]=F[3][0]=F[4][0]=.....=F[n][0]=1;
F[1][0]=F[2][1]=F[3][2]...............F[n][n-1]=1;
转移式:
F[n][k] = F[n-1][k]*(k+1)+F[n-1][k-1]*(n-k)*/

#include<iostream>
using namespace std;

int F[105][105];
int n,k;

void DP()
{
int i,j;
for(i=1; i<=100; ++i)
F[i][0] = F[i][i-1] = 1;
for(i=1; i<=100; ++i)
{
for(j=0; j<i-1; ++j)
{
F[i][j] = (F[i-1][j]*(j+1)+F[i-1][j-1]*(i-j)) % 2009;
}
}
}
int main()
{
DP();
while(cin >> n >> k)
{
cout << F[n][k] << endl;
}
return 0;
}

• 本文已收录于以下专栏：

## HDU 动态规划（46道题目

• 2017年07月24日 10:55
• 24KB
• 下载

## hdu动态规划算法集锦

• 2012年03月21日 16:41
• 10KB
• 下载

## A - Max Sum Plus Plus HDU1024 （ 动态规划 多段连续子段和的最大值）

A - Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St...

## HDU动态规划

• 2014年07月10日 15:39
• 508KB
• 下载

## hdu动态规划题目--杭州电子科技大学oj题目

Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955  背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能...

## HDU 3535 AreYouBusy 题解（动态规划）

http://acm.hdu.edu.cn/showproblem.php?pid=3535

## 【动态规划15】hdu3057 Print Article（斜率优化入门）

• Flanoc
• 2017年06月13日 19:00
• 109

## 动态规划——Hdu_1003_Max Sum

2012/7/22 11:04 Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...