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. Hadoop(七)YARN的资源调度

    一.YARN 概述 YARN 是一个资源调度平台,负责为运算程序提供服务器运算资源,相当于一个分布式的操 作系统平台,而 MapReduce 等运算程序则相当于运行于操作系统之上的应用程序 YARN ...

  2. AC日记——[USACO5.4]奶牛的电信Telecowmunication 洛谷 P1345

    [USACO5.4]奶牛的电信Telecowmunication 思路: 水题: 代码: #include <cstdio> #include <cstring> #inclu ...

  3. 第七章 用户输入和while语句

    大多数编程都旨在解决最终用户的问题,为此通常需要从用户那里获取一些信息.例如,假设有人要判断自己是否到了投票的年龄,要编写回答这个问题的程序,就需要知道用户的年龄,这样才能给出答案.因此,这种程序需要 ...

  4. linux shell awk实现实时监控网卡流量脚本

    goodtools! 原文 awk 'BEGIN{ OFMT="%.3f"; devf="/proc/net/dev"; while(("cat &q ...

  5. <<Javascript Patterns>>阅读笔记 -- 第2章 基本技巧(一)

    第一次写这种东西, 有些生涩和蹩脚, 也是为了自己在表达或是总结方面有所提高, 同时为看过的东西留个痕迹, 以便日后查阅. 有错误或是不妥的地方, 还望各位指正, 谢谢! 第1章 简介 本章主要介绍了 ...

  6. spring_150905_sqlmapclient

    添加ibatis相关的jar包! 实体类: package com.spring.model; public class DogPet { private int id; private String ...

  7. (转)Where与Having的总结

    Where 是一个约束声明,使用Where来约束来之数据库的数据,Where是在结果返回之前起作用的,且Where中不能使用聚合函数. Having 是一个过滤声明,是在查询返回结果集以后对查询结果进 ...

  8. C++运算符重载规则

    运算符重载时要遵循以下规则:  ( 1 ) 除了类属关系运算符 " . " .成员指针运算符 " .* " .作用域运算符 " :: " . ...

  9. dump调试函数

    //dump调试函数if (!function_exists('dump')) { /* * dump调试函数 */ function dump($var) { $traces = debug_bac ...

  10. ref:如何在大量jar包中搜索特定字符

    ref:https://www.cnblogs.com/jiangxinnju/p/5137760.html?utm_source=tuicool&utm_medium=referral 如何 ...