POJ 3934 Queue(DP)
Description
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.
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
题意 linda在一个幼儿园当老师 他要把n个学生排成一列 使仅仅有m对学生可以讲话 当两个学生相邻或者他们之间的全部人都比他们矮时 他们就行讲话
每一个学生的身高都不同
令d[i][j]表示把i个学生排成一列使j对学生可以讲话的方法数
能够把i个学生分成i-1个学生和一个最矮的学生 把这个学生放在i-1个学生中随意两个学生之间都不会影响原来的结果 可是能讲话的学生对数添加了2 有i-2种放法
或者把这个最矮的学生放在两边 这样能讲话的对数仅仅添加了1 有两种放法
所以有转移方程d[i][j]=d[i-1][j-2]*i-2+d[i-1][j-1]*2(j>=2)
j<2时仅仅有d[1][0]=1(学生数大于1就有相邻的就能讲话了) 和d[2][1]=2(学生数大于2肯定不止一对能讲话了)两个有值 能够作为初始条件
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 81, M = 10001;
int d[N][M], n, m;
int main()
{
d[1][0] = 1, d[2][1] = 2;
for (int i = 1; i < N; ++i)
for (int j = 2; j < M; ++j)
d[i][j] = (d[i - 1][j - 2] * (i - 2) + 2 * d[i - 1][j - 1]) % 9937; while (scanf ("%d%d", &n, &m), n)
printf ("%d\n", d[n][m]); return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
POJ 3934 Queue(DP)的更多相关文章
- 周赛 POJ 3934 Queue
Description Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the dinning ...
- Fire (poj 2152 树形dp)
Fire (poj 2152 树形dp) 给定一棵n个结点的树(1<n<=1000).现在要选择某些点,使得整棵树都被覆盖到.当选择第i个点的时候,可以覆盖和它距离在d[i]之内的结点,同 ...
- poj 3140(树形dp)
题目链接:http://poj.org/problem?id=3140 思路:简单树形dp题,dp[u]表示以u为根的子树的人数和. #include<iostream> #include ...
- poj 3249(bfs+dp或者记忆化搜索)
题目链接:http://poj.org/problem?id=3249 思路:dp[i]表示到点i的最大收益,初始化为-inf,然后从入度为0点开始bfs就可以了,一开始一直TLE,然后优化了好久才4 ...
- poj 1088 滑雪 DP(dfs的记忆化搜索)
题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 ...
- poj 3071 可能DP
http://poj.org/problem? id=3071 推方程不难,可是难在怎么算 dp[i][j]表示第i场时第j仅仅队伍存活下来的概率 方程:dp[i][j]=sigma(dp[i-1][ ...
- poj 2342树形dp板子题1
http://poj.org/problem?id=2342 #include<iostream> #include<cstdio> #include<cstring&g ...
- poj上的dp专题
更新中... http://poj.org/problem?id=1037 dp[i][j][0]表示序列长度为i,以j开始并且前两位下降的合法序列数目; dp[i][j][1]表示序列长度为i, 以 ...
- POJ 2096 (概率DP)
题目链接: http://poj.org/problem?id=2096 题目大意:n种bug,s个子系统.每天随机找一个bug,种类随机,来自系统随机.问找齐n种bug,且每个子系统至少有一个bug ...
随机推荐
- Setup Git Server in CentOS 6.3
0. Environment: Server machine: CentOS 6.3 x86 Client machine: Windows 10 Pro x86_64 1. Install ssh ...
- Red Gate系列之三 SQL Server 开发利器 SQL Prompt 5.3.4.1 Edition T-SQL智能感知分析器 完全破解+使用教程
原文:Red Gate系列之三 SQL Server 开发利器 SQL Prompt 5.3.4.1 Edition T-SQL智能感知分析器 完全破解+使用教程 Red Gate系列之三 SQL S ...
- eclipse luna 无法安装veloeclipse问题
问题: 在eclipse 4.4(luna)版本号.安装veloeclipse 2.0.8时,在即将完毕的时候出现下面错误提示: An error occurred while installing ...
- iOS 获取联系人,并调用系统地址簿UI
1.加入 AddressBook库 推断授权状态 -(bool)checkAddressBookAuthorizationStatus { //取得授权状态 ABAuthorizationStatus ...
- Js常用技巧
摘录:http://crasywind.blog.163.com/blog/static/7820316920091011643149/ js 常用技巧 1. on contextmenu=" ...
- Echache整合Spring缓存实例讲解(转)
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要介绍了EhCache,并通过整合Spring给出了一个使用实例. 一.EhCac ...
- jsp简单练习-简单的下拉表单
<%@ page contentType="text/html; charset=gb2312" %> <html> <body> <fo ...
- hdoj 2602 Bone Collector 【01背包】
意甲冠军:给出的数量和袋骨骼的数,然后给每块骨骼的价格值和音量.寻求袋最多可容纳骨骼价格值 难度;这个问题是最基本的01背包称号,不知道的话,推荐看<背包9说话> AC by SWS 主题 ...
- —页面布局实例———win7自己的小算盘
晚上7各地点布局,9点半,刚拿到. 他发现自己专注的时候效率挺高真的哈萨克斯坦.计算器布局前.做了两件简单的页面布局练练手.今晚总体感觉更好,不难. 器之间调试有点蛋疼,真心不想搭理IE. 在进行布局 ...
- UI 纯代码实现计算器
// MHTAppDelegate.h // TestCa // Copyright (c) 2014年 Summer. All rights reserved. #import <UIK ...