poj3934Queue(dp)
来源:互联网 发布:黑蚂蚁网络电视 编辑:程序博客网 时间:2024/06/05 09:16
题目链接:
啊哈哈,点我点我
题意:
有n个幼儿园的孩纸,然后从中找出m对孩子能够让他们看到双方,这样以便他们交流。。
思路:
首先可以考虑把n-1个人已经排成了m-2对,那么只需要把这个最矮的随便插在队伍就可以凑成m对了。另外一种情况是先排成m-1对,然后把最矮的那一个放在对首或者队尾,这样就到了状态转移方程。
if(j>=2)
dp[i][j]=dp[i-1][j-2]*(i-2)
if(j>=1)
dp[i][j]=dp[i][j]+dp[i-1][j-1]*2;
然后最开始把1个人2个人的所有状态枚举出来。。然后对题目中给的范围进行预处理得到所有解,然后直接询问即可。问题就得到了完美的解决。
题目:
Queue
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 406 Accepted: 179
Description
Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the dinning hall is a little bit far away from the classroom, those n kids have to walk in line to the dinning hall every day. When they are walking in line, if and only if two kids can see each other, they will talk to each other. Two kids can see each other if and only if all kids between them are shorter then both of them, or there are no kids between them. Kids do not only look forward, they may look back and talk to kids behind them. Linda don’t want them to talk too much (for it’s not safe), but she also don’t want them to be too quiet(for it’s boring), so Linda decides that she must form a line in which there are exactly m pairs of kids who can see each other. Linda wants to know, in how many different ways can she form such a line. Can you help her?
Note: All kids are different in height.
Note: All kids are different in height.
Input
Input consists of multiple test cases. Each test case is one line containing two integers. The first integer is n, and the second one is m. (0 < n <= 80, 0 <= m <= 10000).
Input ends by a line containing two zeros.
Input ends by a line containing two zeros.
Output
For each test case, output one line containing the reminder of the number of ways divided by 9937.
Sample Input
1 02 03 20 0
Sample Output
104
Source
代码为:
#include<cstdio>#include<cstring>#include<iostream>#define mod 9937using namespace std;int dp[80+10][10000+10];void init(){ memset(dp,0,sizeof(dp)); dp[1][0]=1; dp[2][1]=2; for(int i=3;i<=81;i++) for(int j=1;j<=10001;j++) { if(j>=2) dp[i][j]=(dp[i-1][j-2]*(i-2))%mod; if(j>=1) dp[i][j]=(dp[i][j]+dp[i-1][j-1]*2)%mod; }}int main(){ int n,m; init(); while(~scanf("%d%d",&n,&m)) { if(n==0&&m==0) return 0; cout<<dp[n][m]<<endl; } return 0;}
0 0
- poj3934Queue(dp)
- colors颜色的长度 (来自刘汝佳紫书) dp+dp+dp
- 区间DP -- 石子合并(朴素DP)
- 疯狂 dp(一) 线性 dp
- hdu 3480 Division(DP-DP优化)
- hdu 2196 Computer(DP-树形DP)
- hdu 4044 GeoDefense(DP-树形DP)
- HDOJ-4276(树形DP+背包DP)
- DP·数位DP(2)
- DP·数位DP(4)
- DP·数位DP(5)
- HDU 4001--Dp--(第一道dp)
- bzoj1801(dp棋盘上方案dp)
- POJ2411(状压Dp,插头Dp,数学公式)
- smoj1710:砖块II (dp套dp)
- hdu4336(壮压DP&概率DP)
- HDOJ2571 DP入门题(DP+DFS)
- POJ2796Feel Good(DP)
- NDK在windows下编译libpng
- hdu 1028 Ignatius and the Princess III
- 左旋转字符串
- POJ-1703 Find them, Catch them
- JavaScript学习 jquery16 浏览器版本相关属性
- poj3934Queue(dp)
- 【索引】Lists
- C - Surprising Strings
- 3GPP TS 36.201 V8.3.0 直译
- Android OpenGL ES 开发教程(7):创建实例应用OpenGLDemos程序框架
- JVM加载class文件的原理
- Oracle 绑定变量 详解
- Chrome 被和谐的解决办法
- VC中MessageBox的常见用法