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

答案要模上9937,都会想到是递推吧,关键怎么推。

思路:i个人j对可由    1:i-1个人j-2对再插入一个最小的人,所以对原来的组合没有影响       2:i-2个人j-1对,再在两边插入一个人,对原来的组合也没有影响。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
using namespace std;
const int M=9937;
int dp[85][10005];
void init()
{
dp[1][0]=1;
dp[2][1]=2;
for(int i=3;i<=80;i++)
{
for(int j=0;j<=10000;j++)
{
if(j>=2)
dp[i][j]=(dp[i-1][j-2]*(i-2))%M;
if(j>=1)
dp[i][j]=(dp[i][j]+dp[i-1][j-1]*2)%M;
}
}
}
int main()
{
init();
int n,m;
while(cin>>n>>m)
{
if(n==0&&m==0)
break;
cout<<dp[n][m]<<endl;
}
return 0;
}

周赛 POJ 3934 Queue的更多相关文章

  1. POJ 3934 Queue(DP)

    Queue Description Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the di ...

  2. POJ 3481Double Queue Splay

    #include<stdio.h> #include<string.h> ; ],data[N],id[N],fa[N],size,root; void Rotate(int ...

  3. {POJ}{动态规划}{题目列表}

    动态规划与贪心相关: {HDU}{4739}{Zhuge Liang's Mines}{压缩DP} 题意:给定20个点坐标,求最多有多少个不相交(点也不相交)的正方形 思路:背包问题,求出所有的正方形 ...

  4. [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)

    再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...

  5. poj 3841 Double Queue (AVL树入门)

    /****************************************************************** 题目: Double Queue(poj 3481) 链接: h ...

  6. POJ 3481 Double Queue STLmap和set新学到的一点用法

    2013-08-08 POJ 3481  Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是 ...

  7. POJ 2259 - Team Queue - [队列的邻接表]

    题目链接:http://poj.org/problem?id=2259 Queues and Priority Queues are data structures which are known t ...

  8. poj 2259 Team Queue

    Team Queue Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2977   Accepted: 1092 Descri ...

  9. POJ 3481 Double Queue(Treap模板题)

    Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15786   Accepted: 6998 Des ...

随机推荐

  1. 结构体对齐及#pragma详细解释

    在linux下c语言结构体对齐: 1.自然对齐 struct 是一种复合数据类型,其构成元素既可以是基本数据类型(如int.long.float 等)的变量,也可以是一些复合数据类型(如array.s ...

  2. 如何使用OpenSSL工具生成根证书与应用证书

    如何使用OpenSSL工具生成根证书与应用证书 一.步骤简记 // 生成顶级CA的公钥证书和私钥文件,有效期10年(RSA 1024bits,默认) openssl req -new -x509 -d ...

  3. [笔记] 几个前端bug的解决方案

    jQuery UI下被拖动的元素上飘 症状出现在几乎所有浏览器里.使用 1.10.x 的draggable,在滚动栏下移(即非处于页面顶部)的时候拖动draggable的元素,它会向上跳一段距离.解决 ...

  4. virtualenv python的虚拟环境

    官网:https://virtualenv.pypa.io/en/stable/userguide/ virtualenv通过创建独立Python开发环境的工具, 来解决依赖.版本问题 基本使用: d ...

  5. 谷歌翻译python接口

    项目地址:  https://github.com/ssut/py-googletrans 安装: sudo pip install googletrans 使用: #!/usr/bin/python ...

  6. python开发学习-day02(元组、字符串、列表、字典深入)

    s12-20160109-day02 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  7. spirng boot打包成war部署

    最近一段时间一直在研究和学习springboot,感觉其十分便利好用.以前使用spring搭建项目都整好多繁琐的配置,使用了springboot后这些繁琐的配置统统都不要了.但就是对springboo ...

  8. java 接口请求返回通用json

    public class BaseResponseBody { // 不能添加属性 仅做泛型使用 } public class ResponseBase<T extends BaseRespon ...

  9. 洛谷P4782 【模板】2-SAT问题 [2-SAT]

    题目传送门 [模板]2-SAT问题 题目背景 2-SAT 问题 模板 题目描述 有n个布尔变量 $x_1/~x_n$​ ,另有$m$个需要满足的条件,每个条件的形式都是“ $x_i$ 为$true/f ...

  10. 2017/11/20 Leetcode 日记

    2017/11/14 Leetcode 日记 442. Find All Duplicates in an Array Given an array of integers, 1 ≤ a[i] ≤ n ...