poj3934Queue(dp)
题目链接:
啊哈哈,点我点我
题意:
有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个人的全部状态枚举出来。。
然后对题目中给的范围进行预处理得到全部解。然后直接询问就可以。问题就得到了完美的解决。
题目:
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 406 | Accepted: 179 |
Description
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.
Input
Input ends by a line containing two zeros.
Output
Sample Input
1 0
2 0
3 2
0 0
Sample Output
1
0
4
Source
代码为:
#include<cstdio>
#include<cstring>
#include<iostream>
#define mod 9937
using 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;
}
#include<cstring>
#include<iostream>
#define mod 9937
using 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;
}
poj3934Queue(dp)的更多相关文章
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 初探动态规划(DP)
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...
- Tour(dp)
Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
- Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)
Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...
- 最长公共子序列长度(dp)
/// 求两个字符串的最大公共子序列长度,最长公共子序列则并不要求连续,但要求前后顺序(dp) #include <bits/stdc++.h> using namespace std; ...
随机推荐
- js中的注意事项(持续整理)
1.兼容性 <div class="toutiao_r fl_r" id ="toutiao_r"></div> 这个div中有两个样式 ...
- SDK调试出错小技巧=。=
学习Unity小伙伴完全不懂Android编程抓错误是很困难的..... 1. 使用UnityPlayer.UnitySendMessage(); 发送到Unity使用OnGUI显示错误 2. 直接在 ...
- Co-prime Array&&Seating On Bus(两道水题)
Co-prime Array Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Su ...
- [工作问题总结]MyEclipse 注册
------------------------------ASP.Net+Android+IO开发 .Net培训 期待与您交流!------------------------------ 1.本人 ...
- SQL Server 2000 函数使用---CAST 和 CONVERT
本文来自:http://www.cnblogs.com/xh831213/category/47654.html 将某种数据类型的表达式显式转换为另一种数据类型.CAST 和 CONVERT 提供相似 ...
- Android,使用Json发送数据中,使用的Java转义字符 KanKan原创
kankan原创 与php后台发送数据的时候.要求用到这样的格式. private void sendJson(){ //初始化自己定义的handler CashHandler handler = n ...
- 王立平-Android中对图像进行Base64编码
// ------------------base64-------------------// public String bitmaptoString(Bitmap bitmap) { // 将B ...
- 关于iconfont
1. 从FONT-FACE说起 要想了解iconfont,得从一个新的css3规则说起.css3中,新增了一种样式规则,@font-face,这个规则可以用来引入自定义的字体,到客户端.以前,我们的字 ...
- ThreadPoolExecutor详解
线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为: ThreadPoolExecutor(int corePoolSize, int maxi ...
- 【HeadFirst 设计模式总结】2 观察者模式
作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ 1.我们需要理解报社.订阅系统和订报人之间的关系,订报人通过订阅系统订报,一旦报社有新的报纸,订阅系统就会派人送 ...