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开发框架重构总结
最近一直致力于Winform开发框架的重构工作,因为发现要维护传统Winform开发框架.WCF开发框架.混合式开发框架,以及相关的模块,包括权限管理.字典管理模块.附件管理.人员管理等一些辅助模块, ...
- C#-Windows服務以LocalSystem賬戶安裝的話無法獲取我的文檔路徑
如圖,如果Window服務以上圖 Account安裝運行,則無法獲取到 以下路徑: System.Environment.GetFolderPath(Environment.SpecialFolder ...
- 【循序渐进学Python】7.面向对象的核心——类型(上)
我们知道Python是一门面向对象的脚本语言.从C#的角度来看:首先Python支持多继承.Python 类型成员通常都是public的,并且所有成员函数都是virtual的(可以直接重写). 1. ...
- csharp: Export DataSet into Excel and import all the Excel sheets to DataSet
/// <summary> /// Export DataSet into Excel /// </summary> /// <param name="send ...
- 不经意间网易开源镜像去掉了FreeBSD的镜像
http://mirrors.163.com/ FreeBSD已经到了这么不招人待见的地步了么? 网易曾经可是FreeBSD的大户啊.
- java设计模式--工厂模式
所谓工厂,就是要造产品,比如一个小型砖瓦厂,只有一个窑,既能造砖又能造瓦,这种叫简单工厂模式.规模稍大一点呢,我多个窑,有的窑专门造砖,有的窑专门造瓦,想造别的,比如瓷砖,我再用个专门的窑,这种 ...
- 第三章--Win32程序的执行单元(部分概念及代码讲解)(上 -- 多线程)
学习<Windows程序设计>记录 概念贴士: 1. 线程描述了进程内代码的执行路径. 2. _stdcall是新标准C/C++函数的调用方法.从底层来说,使用这种调用方法参数的进栈顺序和 ...
- Jquery学习笔记:利用jquery获取select下拉框的值
jquery不是特别熟练,每次使用不常用的就要百度,特地记录下来. 我的下拉框是: <div class="form-group"> <select class= ...
- 小白初学ABP框架,着实累啊
这几天在学习ABP相关的知识AutoMapper ,AngularJS,Less,DI(dependencyInjection),EntityFramework code first以及相关NuGet ...
- 硅谷新闻8--TabLayout替换ViewPagerIndicator
1.关联库 compile 'com.android.support:design:23.3.0' 2.布局写上TabLayout <android.support.design.widget. ...