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. SpringMVC由浅入深day02_10拦截器

    10 拦截器 Spring Web MVC 的处理器拦截器类似于Servlet 开发中的过滤器Filter,用于对处理器进行预处理和后处理. 10.1 拦截定义 定义拦截器,实现HandlerInte ...

  2. mongodb 按照时间聚类 java

    当存储到mongodb中的是string类型的时间,小tips: 1. 那么在对此域按照时间聚类(每周,每月)时就不能直接使用mongodb的time关键字了,因为mongodb有自己的时间类型,且目 ...

  3. eclipse下编译cocos2dx 3.0

    先给自己科普一下, android sdk 是给java开发者用的,  咱C++开发者用的是android ndk, 所以就是使用ndk来编译cocos2dx程序了 使用命令行创建一个项目, 我这里创 ...

  4. 在oracle配置mysql数据库的dblink

    本文介绍如何在oracle配置mysql数据库的dblink:虽然dblink使用很占资源:俗称“性能杀手”.但有些场景不得不使用它.例如公司使用数据库是oracle:可能其他部门或者CP合作公司使用 ...

  5. 一句话木马:ASP篇

    ASP一句话木马收集: <%eval request("chopper")%> <%execute request("chopper")%&g ...

  6. Splash evaljs() 方法

    evaljs() 方法可以执行 JavaScript 代码并返回最后一条 JavaScript 语句的返回结果 function main(splash, args) splash:go(" ...

  7. 系统头文件cmath,cstdlib报错

    >C:\Program Files (x86)\Microsoft Visual Studio\\Community\VC\Tools\MSVC\\include\cstdlib(): erro ...

  8. python --->字典 集合 学习笔记

    1.字典--->创建空字典:dict={} broa=["李宁",”耐克“,“阿迪达斯”,“鱼c工作室”] sloga=[“A”,“B”,“C”,“D”] dict={&qu ...

  9. Android 自定义 View 浅析

    Android 自定义 View 浅析 概括 说到自定义 View ,就一定得说说 android 系统的UI绘制流程.再说这个流程之前,我们先看一下在每一个 activity 页面中我们的布局 ui ...

  10. No.4 PyQt学习(页面跳转)

    先定义了两个MainWindow进行跳转,但发现这样的话,从第二个Window无法跳转会第一个.代码如下: # -*- coding: utf-8 -*- import sys from PyQt4. ...