题目链接:

啊哈哈,点我点我

题意:

有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: 65536K
Total 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.

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.

Output

For each test case, output one line containing the reminder of the number of ways divided by 9937. 

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;
}

poj3934Queue(dp)相关推荐

  1. 求三角形最大面积(DP)

    求三角形最大面积(DP) 在OJ上奇迹般WA了:WA:70. Why? #include <iostream> #include <string.h> using namesp ...

  2. LeetCode 编辑距离 II(DP)

    1. 题目 给你两个单词 s 和 t,请你计算出将 s 转换成 t 所使用的最少操作数. 你可以对一个单词进行如下两种操作: 删除一个字符 替换一个字符 注意: 不允许插入操作 题目保证有解 示例: ...

  3. LeetCode 1220. 统计元音字母序列的数目(DP)

    文章目录 1. 题目 2. 解题 1. 题目 给你一个整数 n,请你帮忙统计一下我们可以按下述规则形成多少个长度为 n 的字符串: - 字符串中的每个字符都应当是小写元音字母('a', 'e', 'i ...

  4. LeetCode 265. 粉刷房子 II(DP)

    文章目录 1. 题目 2. 解题 1. 题目 假如有一排房子,共 n 个,每个房子可以被粉刷成 k 种颜色中的一种,你需要粉刷所有的房子并且使其相邻的两个房子颜色不能相同. 当然,因为市场上不同颜色油 ...

  5. LeetCode 256. 粉刷房子(DP)

    文章目录 1. 题目 2. 解题 1. 题目 假如有一排房子,共 n 个,每个房子可以被粉刷成红色.蓝色或者绿色这三种颜色中的一种,你需要粉刷所有的房子并且使其与相邻的两个房子颜色不能相同. 当然,因 ...

  6. LeetCode 1223. 掷骰子模拟(DP)

    1. 题目 有一个骰子模拟器会每次投掷的时候生成一个 1 到 6 的随机数. 不过我们在使用它时有个约束,就是使得投掷骰子时,连续 掷出数字 i 的次数不能超过 rollMax[i](i 从 1 开始 ...

  7. LeetCode 1155. 掷骰子的N种方法(DP)

    1. 题目 这里有 d 个一样的骰子,每个骰子上都有 f 个面,分别标号为 1, 2, -, f. 我们约定:掷骰子的得到总点数为各骰子面朝上的数字的总和. 如果需要掷出的总点数为 target,请你 ...

  8. LeetCode 1139. 最大的以 1 为边界的正方形(DP)

    1. 题目 给你一个由若干 0 和 1 组成的二维网格 grid,请你找出边界全部由 1 组成的最大 正方形 子网格,并返回该子网格中的元素数量.如果不存在,则返回 0. 示例 1: 输入:grid ...

  9. 程序员面试金典 - 面试题 17.23. 最大黑方阵(DP)

    1. 题目 给定一个方阵,其中每个单元(像素)非黑即白. 设计一个算法,找出 4 条边皆为黑色像素的最大子方阵. 返回一个数组 [r, c, size] ,其中 r, c 分别代表子方阵左上角的行号和 ...

最新文章

  1. 每个年龄段,都有每个年龄段的“好”
  2. css 命名规范 BEM
  3. HTML5 WebSocket之HelloWorld
  4. 美国商务部工业和安全局(BIS)发布《关于拟制定脑机接口技术出口管制规则的通知》...
  5. 2、垃圾回收算法(标记清除算法、复制算法、标记整理算法和分代收集算法),各种垃圾收集器讲解(学习笔记)
  6. 个人博客 | 网站部署终极操作:一行命令搞定!
  7. notepad php格式,notepad怎么格式xml
  8. settimeout( )是全局函数吗_JS函数的执行
  9. display: inline-block 布局
  10. 公众号出现该公众号提供的服务出现故障分析
  11. linux需要多少空间安装mysql_如何安装MySQL
  12. jQuery 图像裁剪插件Jcrop
  13. libevent 源码学习五 —— 事件 event
  14. HDU 4675 GCD of Sequence(莫比乌斯反演 + 打表注意事项)题解
  15. 十代主板改win7_微星z490主板装win7系统及bios设置教程(支持10代cpu装win7)
  16. SQLServer中sp_Who、sp_Who2和sp_WhoIsActive介绍和查看监视运行
  17. 第七课GUI练练表面功夫
  18. 光电自动避障小车_凌鸟智能总结了一下激光导航反射板AGV小车的优缺点!
  19. Qt Moc及信号-槽源代码解析
  20. Chrome无头模式获取直播间弹幕

热门文章

  1. 流控制传输协议 SCTP
  2. php原生 文章浏览量,调用WordPress函数统计文章访问量及PHP原生计数器的实现
  3. matlab bp神经网络
  4. 【 C 】翻译与执行
  5. scala学习笔记-面向对象编程之Trait
  6. windows下php7.1安装redis扩展以及redis测试使用全过程
  7. 注意Class类的特殊性
  8. cocos2dx3.8 android打包脚本编写
  9. mysql数据库锁定机制
  10. Windows下oracle RMAN备份脚本