sicily1687. Permutation

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


参考代码:

// Problem#: 1687
// Submission#: 2194498
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    const int maxn = 102;
    const int maxk = 102;
    int n, k;
    long long int dp[maxn][maxk];
    while (cin >> n >> k)
    {
        memset(dp, 0, sizeof(dp));
        for (int i = 1; i <= n; ++ i)
        {
            dp[i][0] = 1;
            dp[i][i - 1] = 1;
        }
        for (int i = 1; i <= n; ++ i)
        {
            for (int j = 1; j <= k; ++ j)
            {
                dp[i][j] = (dp[i - 1][j - 1] * (i - 1 - (j - 1)) + dp[i - 1][j] * (j + 1)) % 2007;
            }
        }
   
        cout << dp[n][k] % 2007 << endl;
    }
}                                 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值