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. [原]unity3d GLSL无法pc上显示

    pc编写GLSL: Shader "Custom/GLSL" {    Properties {        _MainTex ("Base (RGB)", ...

  2. [原]C# 常用函数统计

    1.获取MD5 string MD5Compute(string strPwd) { MD5CryptoServiceProvider m5 = new MD5CryptoServiceProvide ...

  3. 大杂烩 -- Iterator 和 Iterable 区别和联系

    基础大杂烩 -- 目录 用Iterator模式实现遍历集合  Iterator模式是用于遍历集合类的标准访问方法.它可以把访问逻辑从不同类型的集合类中抽象出来,从而避免向客户端暴露集合的内部结构. 例 ...

  4. Linux环境SVN命令行使用经验总结(转)

    在windows机器上开发得差不多了之后,打包传送到开发机编译,在开发机上解决编译错误. [缺点] 浪费时间在打包解包,机器间传输代码. 在windows机器上开发之后,check in代码进分支,在 ...

  5. java.security.NoSuchAlgorithmException: SHA1PRNG SecureRandom not available

    好久没有使用MyEclipse10了,今天打开看了以前大学的项目,在Tomcat7中发布启动,我嚓嘞,报错: SEVERE: Exception initializing random number ...

  6. MHL相关资源链接

    http://www.mhlconsortium.org/ 消费者网站: www.meetmhl.com采用者网站:www.mhltech.org 博客http://blog.sina.com.cn/ ...

  7. mybatis 之 parameterType="list"

    <!-- 根据货品编号查找货品图片地址,货品ID,商品ID,货品名称 --> <select id="getGoodsInfoByGoodsNo" paramet ...

  8. Java 实现文件批量重命名亲测可用(精简版)

    package com.cmge.utils; import java.io.*; import java.util.*; import java.util.Map.Entry; import com ...

  9. 【Web前端开发最佳实践系列】标准的HTML代码

    一.验证代码是否符合标准 优点: 标准的页面会保证浏览器正确的渲染 网页能更容易被搜索引擎搜索,提高网站的搜索排名 提高网站的易用性 网页更好维护和扩展 常用工具: W3 Validator HTML ...

  10. 【Java基础】StringTokenizer用法

    写在前面 因为最近在接触hadoop的东西,看示例WordCount的时候里面有一个StringTokenizer的东西特地看了一下 The string tokenizer class allows ...