HDU 2583 permutation
来源:互联网 发布:购买域名和空间 编辑:程序博客网 时间:2024/06/01 10:19
题目网站
HDU 2583 permutation
Problem DescriptionPermutation 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
题意为告诉我们n个排列求其中含有k个'<'的排列数目mod2009是多少
思路:开始2了,都想到边上了给成功绕过去了
设dp[i][j]表示的是i个排列有k个<
设前N-1个的情况已经全部知道
则对于N,k个<来说就是有
1:前N-1个的k个将N放到最左边以及a<b和a<n>b,所以前dp[i-1][j]的情况乘以可以k的个数加1
2:对于前N-1个的k-1个有a>b
插入N:a<N>b增加了一个<故有
方程dp[i][j]=dp[i-1][j]*(j+1)+dp[i-1][j-1]*(i-j);
代码如下:
0 0
- HDU 2583 permutation
- hdu-2583 permutation
- HDU 2583 permutation
- hdu 2583 permutation 好题 递推
- hdu 4345 Permutation
- Hdu 4345 Permutation
- hdu 2404 Permutation Recovery
- HDU 4917 Permutation
- HDU 3664 Permutation Counting
- HDU 4345 Permutation dp
- HDU 3667 Permutation Counting
- hdu 5753 Permutation Bo
- HDU 5753 Permutation Bo
- HDU-5753-Permutation Bo
- HDU 5753 Permutation Bo
- 【HDU】5753 Permutation Bo
- HDU 5789 Permutation
- 【HDU】5789 Permutation【dp】
- HTTP请求报文和HTTP响应报文 http://blog.csdn.net/zhangliang_571/article/details/23508953
- Nmap新增脚本http-svn-enum和http-svn-info
- SSH中各种形式的取值方式
- Mtalab--数据拟合
- 按层次方式打印二叉树
- HDU 2583 permutation
- 使用X-UA-Compatible来设置IE浏览器兼容模式
- 装饰者设计模式
- 关于std::function和std::bind绑定成员函数
- Android开发设计模式
- POJ 1654 Area(计算几何)
- 网络爬虫基本原理二
- 关于Vuforia 4.2.3水印出现问题以及怎么消除?
- python recv在连接断开后会变为非阻塞