hdu 2583 permutation
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的更多相关文章
- hdu 2583 permutation 动态规划
Problem Description Permutation plays a very important role in Combinatorics. For example ,1 2 3 4 ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- hdu 5753 Permutation Bo 水题
Permutation Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 3811 Permutation 状压dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3811 Permutation Time Limit: 6000/3000 MS (Java/Othe ...
- HDU 6628 permutation 1 (暴力)
2019 杭电多校 5 1005 题目链接:HDU 6628 比赛链接:2019 Multi-University Training Contest 5 Problem Description A s ...
- HDU 4345 Permutation dp
Permutation Problem Description There is an arrangement of N numbers and a permutation relation that ...
- hdu 5753 Permutation Bo
这里是一个比较简单的问题:考虑每个数对和的贡献.先考虑数列两端的值,两端的摆放的值总计有2种,比如左端:0,大,小:0,小,大:有1/2的贡献度.右端同理. 中间的书总计有6种可能.小,中,大.其中有 ...
- 【数学】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为真则为 ...
- HDU 6044--Limited Permutation(搜索+组合数+逆元)
题目链接 Problem Description As to a permutation p1,p2,⋯,pn from 1 to n, it is uncomplicated for each 1≤ ...
随机推荐
- WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用
WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用 转自:http://www.cnblogs.com/wuhuacong/arch ...
- 环信SDK与Apple Watch的结合(2)
这一篇主要是介绍怎么拖apple watch上的相关页面,附源码EMWatchOCDemo. 需要在工程中的“EMWatchOCDemo WatchKit App”中进行操作,该文件夹的结构如图 Wa ...
- JS获取html对象的几种方式说明
document.getElementById("zx"); 通过ID获取html元素对象,ID号在html文档当中应该是唯一的.返回的是唯一element对象.并且所有浏览器都兼 ...
- BI之SSAS完整实战教程2 -- 开发环境介绍及多维数据集数据源准备
上一篇我们已经完成所有的准备工作,现在我们就开始动手,通过接下来的三篇文章创建第一个多维数据集. 传统的维度和多维数据集设计方法主要是基于现有的单源数据集. 在现实世界中,当开发商业智能应用程序时,很 ...
- XMLHelper.cs
http://yunpan.cn/Q7czcYTwE8qkc 提取码 545c using System; using System.Linq; using System.Xml.Linq; usi ...
- Docker on CentOS for beginners
Introduction The article will introduce Docker on CentOS. Key concepts Docker Docker is the world's ...
- 一个SpringMVC简单Demo中出现的错误
最近在学springmvc 一个简答的Springmvc配置包括如下步骤: 1.在 web.xml 文件中配置 DispatcherServlet (该中央控制器相当于 MVC 模式中的 C),还可以 ...
- 多准则决策模型-TOPSIS评价方法-源码
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ...
- pace.js和NProgress.js两个加载进度插件的一点小总结
这两个插件都是关于加载进度动画的,应该说各有特点吧,最起码对我来说是各有优势的.今天一天就捣鼓了加载进度动画,也研究了大量的(也就这两个)加载进度动画,也算对加载进度动画有了一个初步的了解了吧. NP ...
- Egret Engine(白鹭引擎)介绍及windows下安装
Egret Engine简要介绍----- Egret Engine(白鹭引擎)[Egret Engine官网:http://www.egret-labs.org/]是一款使用TypeScript语言 ...