permutation

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

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 2009 on a line.

Sample Input

5 2

Sample Output

66

#include <iostream>

using namespace std;
const int m=2009;
int dp[110][110]; int main()
{
int n,k,i,j; //预处理
for(i=0;i<=100;i++)
{
dp[i][0]=1;
dp[i][i]=0;
}
for(i=1;i<=100;i++)
for(j=1;j<i;j++)
if(j==i-1)//k==n-1时,结果为1
dp[i][j]=1;
else//状态转移方程dp[i][j]=(j+1)*dp[i-1][j]+(i-j)*dp[i-1][j-1];
dp[i][j]=((j+1)*dp[i-1][j]%m+(i-j)*dp[i-1][j-1]%m)%m; while(cin>>n>>k)
if(k>n)//n>=k时,结果必为0
cout<<'0'<<endl;
else
cout<<dp[n][k]<<endl; return 0;
}

hdu 2583 permutation的更多相关文章

  1. hdu 2583 permutation 动态规划

    Problem Description Permutation plays a very important role in Combinatorics. For example ,1 2 3 4  ...

  2. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  3. hdu 5753 Permutation Bo 水题

    Permutation Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  4. HDU 3811 Permutation 状压dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3811 Permutation Time Limit: 6000/3000 MS (Java/Othe ...

  5. HDU 6628 permutation 1 (暴力)

    2019 杭电多校 5 1005 题目链接:HDU 6628 比赛链接:2019 Multi-University Training Contest 5 Problem Description A s ...

  6. HDU 4345 Permutation dp

    Permutation Problem Description There is an arrangement of N numbers and a permutation relation that ...

  7. hdu 5753 Permutation Bo

    这里是一个比较简单的问题:考虑每个数对和的贡献.先考虑数列两端的值,两端的摆放的值总计有2种,比如左端:0,大,小:0,小,大:有1/2的贡献度.右端同理. 中间的书总计有6种可能.小,中,大.其中有 ...

  8. 【数学】HDU 5753 Permutation Bo

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 题目大意: 两个序列h和c,h为1~n的乱序.h[0]=h[n+1]=0,[A]表示A为真则为 ...

  9. HDU 6044--Limited Permutation(搜索+组合数+逆元)

    题目链接 Problem Description As to a permutation p1,p2,⋯,pn from 1 to n, it is uncomplicated for each 1≤ ...

随机推荐

  1. 译:c#生成条码的web控件

    译文:http://www.codeproject.com/Tips/846860/Csharp-Barcode-Generator-Web-Control 在asp.net的web页用c#的web控 ...

  2. 转帖一篇sixxpack破解的文章!

    星期天闲着没事玩游戏,玩游戏不能无外挂.于是百度了半天,找到了一个,看介绍貌似不错,就下载了下来.一看,竟然是用.net写的,下意识地Reflector了一下.发现竟是一个叫actmp的程序集.如图: ...

  3. Eclipse颜色主题插件:Eclipse Color Theme

    一个很赞的eclipse插件,可以简单方便地实现eclipse下的代码配色.另外插件作者还专门为此插件做了一个eclipse配色网站,配色多达728个,开发者们也可以在此网站分享自己的配色方案. 插件 ...

  4. SqlServer 2008 R2定时备份数据库,并且发送邮件通知

    先配置数据库的邮件设置,这样才可以发送邮件. 2. 3. 4. 5. 6. 7. 8. 9. 10. 总的预览图,如图 执行这一段(先发送备份邮件,然后进行数据备份,将昨天的发送数据插入到另一张表中, ...

  5. phpwind的rewrite重写原理

    没有深入过pw,被人问到这方面的问题,搜索了一下,发现了一篇博文,但原博客已打不开. http://www.phpsoho.com/html/document/200608/1154750694.ht ...

  6. SharpGL学习笔记(十四) 材质:十二个材质球

    材质颜色 OpenGL用材料对光的红.绿.蓝三原色的反射率来近似定义材料的颜色.象光源一样,材料颜色也分成环境.漫反射和镜面反射成分,它们决定了材料对环境光.漫反射光和镜面反射光的反射程度.在进行光照 ...

  7. online judge(ACM) 的设计与分析 (有c#demo)

    ACM.OJ,算法在线判题系统. 帮朋友完成毕业设计而写的,软件环境windows系统,语言是C# winform(因为我不熟悉asp.net,现在暂用winform写的demo). 看了下其他相关论 ...

  8. android studio :com.android.support:appcompat-v7:21.+ 报错

    android studio :com.android.support:appcompat-v7:21.+ 报错: 在project——>app——>build.gradle修改: app ...

  9. winform(多窗体、菜单和工具栏)

    一.多窗体 1.哪个是主窗体 利用From1的button将From2打开 private void button1_Click(object sender, EventArgs e) { Form2 ...

  10. cl_gui_cfw=>dispatch

    将已经触发的EVENT发送给他们各自的EVENT HANDLER,以便让这些事件得到响应. 根据返回值可以判断是否发送成功. CALL METHOD cl_gui_cfw=>dispatch   ...