(POJ1953)World Cup Noise(dp)
来源:互联网 发布:淘宝客服卖家幽默对话 编辑:程序博客网 时间:2024/06/04 19:33
World Cup Noise
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 16006 Accepted: 7904
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).
"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.
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
231
Sample Output
Scenario #1:5Scenario #2:2
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>using namespace std;#define maxn 50#define inf 0x3f3f3f3fint n,m;int dp[maxn][2];int main(){ dp[1][0]=1; dp[1][1]=1; for(int i=2;i<=45;i++){ dp[i][0]=dp[i-1][0]+dp[i-1][1]; dp[i][1]=dp[i-1][0]; } int t; //freopen("in.txt","r",stdin); scanf("%d",&t); int tt=0; while(tt<t){ scanf("%d",&n); printf("Scenario #%d:\n%d\n",++tt,dp[n][0]+dp[n][1]); }}
0 0
- (POJ1953)World Cup Noise(dp)
- (POJ1953)World Cup Noise
- POJ1953 World Cup Noise DP水题
- POJ1953 World Cup Noise
- POJ1953 World Cup Noise
- poj - 1953 - World Cup Noise(dp)
- poj 1953 World Cup Noise(DP)
- 【POJ1953】World Cup Noise(动态规划,斐波那契数列)
- POJ 1953 World Cup Noise(数位DP 01串)
- pku 1953 World Cup Noise(DP)
- pku 1953 -- World Cup Noise (DP)
- poj 1953 World Cup Noise DP
- POJ-World Cup Noise 简单DP
- poj 1953 World Cup Noise (数学:推导)
- POJ 1953 World Cup Noise (递推)
- POJ-1953 World Cup Noise(线性动规)
- pku_1953 World Cup Noise
- PKUOJ1593 World Cup Noise
- 首字母变大写 HDU 2026
- 51单片机寄存器
- 第4周项目4-指向学生类的指针
- 一个安卓初学者的求知欲
- Java系列-Http同步和异步请求区别
- (POJ1953)World Cup Noise(dp)
- ftp服务器搭建
- ipython[notebook]安装(windows平台)
- [Unity插件]使用iTween使物体沿曲线运动
- C语言 编写程序实现字符串比较,不允许使用strcmp函数。
- 第4周项目2分数类的雏形
- Android的四大组件
- NYOJ---题目95众数问题
- 遍历Hashtable的几种方法