World Cup Noise

Time Limit: 1000MS Memory Limit: 30000K

Total Submissions: 16374 Accepted: 8097

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

注意结果int存不下。简单的动规,递推即可

#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h> using namespace std;
int n;
long long int dp[50][2];
int main()
{
int a;
while(scanf("%d",&a)!=EOF)
{
int cas=0;
while(a--)
{
memset(dp,0,sizeof(dp));
dp[1][0]=1;
dp[1][1]=1;
scanf("%d",&n);
for(int i=2;i<=n;i++)
{
dp[i][1]+=dp[i-1][0];
dp[i][0]+=(dp[i-1][0]+dp[i-1][1]);
}
printf("Scenario #%d:\n",++cas);
printf("%lld\n\n",dp[n][1]+dp[n][0]);
} }
return 0;
}

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

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

  3. poj 1953 World Cup Noise (dp)

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

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

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

  5. HOJ 2156 &POJ 2978 Colored stones(线性动规)

    Colored stones Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1759 Accepted: 829 Descrip ...

  6. POJ 1953 World Cup Noise(递推)

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

  7. POJ-1958 Strange Towers of Hanoi(线性动规)

    Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2677 Accepted: 17 ...

  8. POJ-1458 Common Subsequence(线性动规,最长公共子序列问题)

    Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44464 Accepted: 18186 ...

  9. POJ--1050--To the Max(线性动规,最大子矩阵和)

    To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44723 Accepted: 23679 Descript ...

随机推荐

  1. hibernate 之 sql查询

    如果用hibernate执行原生sql进行数据查询可以调用 SQLQuery query = getSession().createSQLQuery(sql); 然后再执行 query.list() ...

  2. 在Linux上安装jdk,mysql,tomcat的准备工作

    准备工作: 因为JDK,TOMCAT,MYSQL的安装过程中需要从网上下载部分支持包才可以继续,所以要提前安装下载好下面四个依赖 yum install glibc.i686 yum -y insta ...

  3. ios开发之--比较两个数组里面的值是否相同

    比较两个数组里面的内容是否相同,代码如下: NSArray *array1 = [NSArray arrayWithObjects:@"a", @"b", @& ...

  4. ckeditor4.4.6添加代码高亮

    研究了很久才发现,在 ckeditor4.4.6中添加代码高亮超级简单啊,下面直接上过程 ckeditor4.4.6支持自定义代码高亮,利用Code Snippet插件并默认启用highlight.j ...

  5. iOS 解决UIScrollView布局问题(布局受statusBar和NavigationBar影响)

    iOS APP中有一个非常好用的功能,那就是当我们在滚动一个UIScrollView滚动了很远很远的时候,假如我们想让UIScrollView回到顶部,我们绝大多数人的做法就是慢慢慢慢的滚动UIScr ...

  6. 我的WAF Bypass实战系列

    ​ 梳理了一下自己写过的WAF Bypass相关的文章,按照编写时间顺序,整理成了一个WAF Bypass实战系列,如果你准备了解WAF攻防这一块的内容,可以来了解一下. 第一篇:<Bypass ...

  7. iOS开发--打印NSRange,CGRect等结构体

    使用对应的转换NSStringFromCGPoint   NSStringFromCGSize   NSStringFromCGRect  NSStringFromCGAffineTransform  ...

  8. vue再次入手(数据传递①)

    准备 之前使用vue.js完成一个项目之后,对其还是充满着无限兴趣,于是不妨利用碎片时间再次研究一下这个“令人着迷”的js框架. 1.新建一个基于vue的项目,具体方法不再赘述,请看这里:http:/ ...

  9. 微信-苹果机无法播放声音Audio

    今天同事测试活动的时候,背景音效(多个)苹果机无法发出声音,几个手机都试过,没什么用.不过安卓机上倒是没这个问题,正常. 最开始以为是js冲突问题,将页面上所有的东西进行加处理(清空,一个个加进来), ...

  10. JS使用中碰到的一些问题

    settimeout: 1.setTimeout(function () {//这个则会在1秒后进行弹出1 alert(1); }, 1000); 2.setTimeout(alert(1), 100 ...