World Cup Noise
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 14397   Accepted: 7129

Description

Background 
"KO-RE-A, KO-RE-A" shout 54.000 happy football fans after their team has reached the semifinals of the FIFA World Cup in their home country. But although their excitement is real, the Korean people are still very organized by nature. For example, they have organized huge trumpets (that sound like blowing a ship's horn) to support their team playing on the field. The fans want to keep the level of noise constant throughout the match. 
The trumpets are operated by compressed gas. However, if you blow the trumpet for 2 seconds without stopping it will break. So when the trumpet makes noise, everything is okay, but in a pause of the trumpet,the fans must chant "KO-RE-A"! 
Before the match, a group of fans gathers and decides on a chanting pattern. The pattern is a sequence of 0's and 1's which is interpreted in the following way: If the pattern shows a 1, the trumpet is blown. If it shows a 0, the fans chant "KO-RE-A". To ensure that the trumpet will not break, the pattern is not allowed to have two consecutive 1's in it. 
Problem 
Given a positive integer n, determine the number of different chanting patterns of this length, i.e., determine the number of n-bit sequences that contain no adjacent 1's. For example, for n = 3 the answer is 5 (sequences 000, 001, 010, 100, 101 are acceptable while 011, 110, 111 are not).

Input

The first line contains the number of scenarios. 
For each scenario, you are given a single positive integer less than 45 on a line by itself.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the number of n-bit sequences which have no adjacent 1's. Terminate the output for the scenario with a blank line.

Sample Input

2
3
1

Sample Output

Scenario #1:
5 Scenario #2:
2
题目大意:求一个长度为n的由0和1组成的序列中满足没有两个1相邻的序列的数目。
解题方法:用动态规划可以很简单的解答出本题,dp方程为dp[i] = dp[i - 1] + dp[i - 2],一开始我也不明白这道题为什么是这样解答的,其实思想是这样子的,当一个长度为n - 1的01串变为长度为n的01串的时候,在后面添加一个0是没有问题的,添加一个1的组合数其实就是长度为n - 1的01串的组合数,而在后面添加一个1则必须要求长度为n - 1的01串最后一位必须为0,组合数和长度为n - 2的01串是一样的,所以dp方程为dp[i] = dp[i - 1] + dp[i - 2]。
#include <stdio.h>
#include <iostream>
using namespace std; int main()
{
int dp[] = {, , , };
int n, x, nCase;
for (int i = ; i <= ; i++)
{
dp[i] = dp[i - ] + dp[i - ];
}
scanf("%d", &n);
nCase = ;
while(n--)
{
scanf("%d", &x);
printf("Scenario #%d:\n%d\n\n", ++nCase, dp[x]);
}
return ;
}
 
												

POJ 1953 World Cup Noise的更多相关文章

  1. Poj 1953 World Cup Noise之解题报告

    World Cup Noise Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16369   Accepted: 8095 ...

  2. poj 1953 World Cup Noise (dp)

    World Cup Noise Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16774   Accepted: 8243 ...

  3. poj - 1953 - World Cup Noise(dp)

    题意:n位长的01序列(0 < n < 45),但不能出现连续的两个1,问序列有多少种. 题目链接:id=1953" target="_blank">h ...

  4. POJ 1953 World Cup Noise(递推)

    https://vjudge.net/problem/POJ-1953 题意:输入一个n,这n位数只由0和1组成,并且不能两个1相邻.计算共有多少种排列方法. 思路:递推题. 首先a[1]=2,a[2 ...

  5. POJ-1953 World Cup Noise(线性动规)

    World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16374 Accepted: 8097 Desc ...

  6. Poj 3117 World Cup

    1.Link: http://poj.org/problem?id=3117 2.Content: World Cup Time Limit: 1000MS   Memory Limit: 65536 ...

  7. poj1953 World Cup Noise

    http://poj.org/problem?id=1953 题目大意:给定一个正整数n,确定该长度的不同吟唱模式的数量,即确定不包含相邻1的n位序列的数目.例如,对于n = 3,答案是5 (序列00 ...

  8. POJ 1953

    //FINBONACI数列 #include <iostream> #define MAXN 100 using namespace std; int _m[MAXN]; int main ...

  9. 【dp】 poj 1953

    用n个数字0或者1组成一个排列,要求每两个1不相邻,问有多少种排法 dp[n][0]记录n个连续数,结尾为0的不同排列数dp[n][1]记录第n个连续数,结尾为1的不同排列数 DP公式: dp[i][ ...

随机推荐

  1. JavaScript_5_对象

    1. JavaScrip中所有事物都是对象:字符串.数字.日期.等等 2. 在javaScripe中,对象是拥有属性和方法的数据 <!DOCTYPE html> <html> ...

  2. Mysql-数据库及数据表结构和操作

    1.数据库系统:数据库系统是用来维护和管理数据库的系统工具,数据库系统拥有自己的用户名和密码 1.1.显示该系统中的数据库:Show databases; 1.2.创建数据库:Create datab ...

  3. 51nod 1693 水群

    基准时间限制:0.4 秒 空间限制:524288 KB 分值: 160 难度:6级算法题  收藏  关注 总所周知,水群是一件很浪费时间的事,但是其实在水群这件事中,也可以找到一些有意思的东西. 比如 ...

  4. 10款免费的MySQL数据库图形化管理工具

    绝大多数的关系数据库都明显不同于MS Access,它们都有两个截然不同的部分:后端作为数据仓库,前端作为用于数据组件通信的用户界面.这种设计非常巧妙,它并行处理两层编程模型,将数据 层从用户界面中分 ...

  5. 用GWT开发的HelloGWT程序

    GWT项目可以通过 命令行和Eclipse插件两种方法创建.创建GWT项目的命令是webAppCreator,具体使用方法可以看GWT的开发文档. Eclipse插件安装完成后,Eclipse的工具条 ...

  6. python之golbal/nonlocal

    一.关键字 golbal nonlocal 在局部修改全局的变量为什么会报错 count = 0 def func(): count += 1 func() # UnboundLocalError: ...

  7. Ubuntu编译Android源码过程中的空间不足解决方法

    Android源码一般几十G,就拿Android5.0来说,下载下来大概也有44G左右,和编译产生的文件以及Ubuntu系统占用的空间加起来,源码双倍的空间都不够有.编译源码前能分配足够的空间再好不过 ...

  8. linux配置邮件客户端

    linux配置邮件客户端 1. 申请一个163邮箱,并配置客户端授权密码 l 开启POP3/SMTP/IMAP l 设置客户端授权密码 ###此密码不能跟邮箱密码相同,此密码用来在linux邮件客户端 ...

  9. Xcode开发技巧

    1.Xcode 中的 Code Snippets 默认放在下面的目录中: ~/Library/Developer/Xcode/UserData/CodeSnippets 2.自定义的代码背景颜色和代码 ...

  10. 如何用VS2017用C++语言写Hello world 程序?

    1,首先,打开VS2017. 2,左上角按文件——新建——项目,或按ctrl+shift+n. 3,按照图片里的选,选完按“确定”. 4,右键“源文件”,再按添加——新建项. 5,剩下的就很简单了,只 ...