题目链接:

啊哈哈,点我点我

题意:

有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. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  2. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  3. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  4. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  5. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  6. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  7. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

  8. Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)

    Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...

  9. 最长公共子序列长度(dp)

    /// 求两个字符串的最大公共子序列长度,最长公共子序列则并不要求连续,但要求前后顺序(dp) #include <bits/stdc++.h> using namespace std; ...

随机推荐

  1. Zookeeper 5、Zookeeper应用场景

    应用场景1 .统一命名服务 » 分布式应用中,通常需要有一套完整的命名规则,既能够产生唯一的名称又便于人识别和记住,通常情况 下用树形的名称结构是一个理想的选择,树形的名称结构是一个有层次的目录结构, ...

  2. UGUI Image控件

    今天一起学习Image控件O(∩_∩)O~ 介绍一下基本的属性 Source:Image:               指定图片源, 图片设置2DSprite(2D and UI)格式Color:   ...

  3. 网络编程API-下 (I/O复用函数)

    IO复用是Linux中的IO模型之中的一个,IO复用就是进程预先告诉内核须要监视的IO条件,使得内核一旦发现进程指定的一个或多个IO条件就绪,就通过进程进程处理.从而不会在单个IO上堵塞了. Linu ...

  4. 【巧妙消维DP】【HDU2059】龟兔赛跑

    龟兔赛跑 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  5. centos上node.js的安装

    CentOS 下安装 Node.js 1.下载源码,你需要在https://nodejs.org/en/download/下载最新的Nodejs版本,本文以v0.10.24为例: cd /usr/lo ...

  6. VLC播放器架构剖析

    VLC采用多线程并行解码架构,线程之间通过单独的一个线程控制所有线程的状态,解码器采用filter模式.组织方式为模块架构 模块简述:libvlc                  是VLC的核心部分 ...

  7. 第二章实例:ArrayAdapter结合ListView列表视图

    package mydefault.packge; import com.example.codeview.R; import android.app.Activity; import android ...

  8. mvc 微软票据验证

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  9. UIView--UIImageView

    1.contentMode view.contentMode = UIViewContentModeScaleAspectFill; 2.是否实现触摸 3.简单实现动画 图片的名字为campFire0 ...

  10. WebConfig

    花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <? ...