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 2007 on a line.
 
Sample Input
5 2
 
Sample Output
66
 

题意大概就是求n的全排列中,用大于小于号连接,其中小于号有k个的情况有多少种。注意,ac代码是%2009,不是2007

显然n的全排列有n!个,考虑下dp算法

状态转移是DP(n,k)=dp(n-1,k)*(k+1)+dp(n-1)(k-1)*(n-k)

n代表考虑n个数字的状态,k代表小于号的个数。

先作特殊情况,序列1 2 3 4 5 6,一共5个小于号,如果我要加入数字7,那么我有7种加法,并且只有一种加法会使小于号+1.

序列a1 a2 a3 a4 a5 ……a(n-1),一共有n-1个数字,有k个小于号,那么我加入an有n种加法,其中会使小于号+1的有n-k种(就是加在大于号的位置上),其他的k+1种不会改变小于号的个数。

#include<stdio.h>
int main()
{
int n,k,i,j,s;
int dp[][];
for(i=;i<=;i++)
{
dp[i][]=;
dp[][i]=;
} while(scanf("%d%d",&n,&k)!=EOF)
{
for(i=;i<=;i++)
for(j=;j<=;j++)
{ dp[i][j]=(dp[i-][j]*(j+)+dp[i-][j-]*(i-j))%;
}
printf("%d\n",dp[n][k]);
}
}
 

hdu 2583 permutation 动态规划的更多相关文章

  1. hdu 2583 permutation

    permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  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 3535] AreYouBusy (动态规划 混合背包 值得做很多遍)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3535 题意:有n个任务集合,需要在T个时间单位内完成.每个任务集合有属性,属性为0的代表至少要完成1个 ...

  9. [HDU 1114] Piggy-Bank (动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 简单完全背包,不多说. #include <cstdio> #include < ...

随机推荐

  1. [Redux] Store Methods: getState(), dispatch(), and subscribe()

    console.clear(); const counter = (state = 0, action) => { switch (action.type) { case 'INCREMENT' ...

  2. TinyXml高速入门(一)

    作者:朱金灿 来源:http://blog.csdn.net/clever101 对于xml文件,眼下我的工作仅仅是集中在配置文件和作为简单的信息文件来用,因此我不太喜欢使用msxml这样的重量级的x ...

  3. 新浪微博开放平台OAuth授权解决方案(含代码)

    前几日一位朋友项目中需要使用新浪微博的接口,故和这位朋友一同研究了新浪微博开放平台上面所提供的资料,首先要使用这些接口是需要用户登录并且授权的,新浪微博开放平台其实是提供两种授权方式的,第一种是:OA ...

  4. 大型系统开发sql优化总结(转)

    Problem Description: 1.每个表的结构及主键索引情况 2.每个表的count(*)记录是多少 3.对于创建索引的列,索引的类型是什么?count(distinct indexcol ...

  5. android获取在res文件下的图片资源

    //得到该图片的id(name 是该图片的名字,"drawable" 是该图片存放的目录,getPackageName()是应用程序的包) int resID = getResou ...

  6. office2010删除多余空行

    选择 ctrl+H,弹出 "查找和替换"对话框,在"查找内容"输入"^p^p",并在"替换为"输入"^p&qu ...

  7. Java sql helper[转]

    原文:http://www.cnblogs.com/beijiguangyong/archive/2011/12/10/2302737.html package sql; import java.sq ...

  8. osgi与webservice

    osgi简介: http://osgia.com/ http://blog.csdn.net/xiaokui008/article/details/9662933 http://wdhdd889.it ...

  9. 修改SELinux设置,使vsftp在enforcing security enhance模式下正常运行

    开了SELinux和防火墙,没想到引出了vsftp的问题.FTP登录报错:500 OOPS: cannot change directory.下面来看看产生这个问题的原因和对策. 首先,分析一下冲突原 ...

  10. Windows Server 2008关闭internet explorer增强的安全配置

    服务器系统要求很高的安全性,所以微软给ie添加了安全增强.这就使得ie在Internet区域的安全级别一直是最高的,而且无法进行整体调整. 关闭IE SEC服务器系统要求很高的安全性,所以微软给ie添 ...