POJ 1953 World Cup Noise(数位DP 01串)
来源:互联网 发布:雕刻软件有哪些 编辑:程序博客网 时间:2024/05/23 17:52
World Cup Noise
Time Limit: 1000MS
Memory Limit: 30000KTotal Submissions: 17861
Accepted: 8707
Memory Limit: 30000KTotal Submissions: 17861
Accepted: 8707
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
Source
TUD Programming Contest 2002, Darmstadt, Germany
题目大意:给出一个数n,求n位二进制中有多少个数不包含相邻的1.
dp[i][0]表示长度位i的二进制当前位为0能有多少个数.
dp[i][1]表示长度位i的二进制当前位为1能有多少个数.
很容易可以得到方程:
dp[i][0] = dp[i - 1][0] + dp[i - 1][1],
dp[i][1] = dp[i - 1][0]
答案自然就是dp[n][0] + dp[n][1]
AC代码#include<iostream>#include<cstdio>using namespace std;int dp[50][2];int main(){int t;scanf("%d",&t);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 n;for(int i=1;i<=t;i++){scanf("%d",&n);printf("Scenario #%d:\n",i);printf("%d\n\n",dp[n][0]+dp[n][1]);}return 0;}
阅读全文
1 0
- POJ 1953 World Cup Noise(数位DP 01串)
- poj - 1953 - World Cup Noise(dp)
- poj 1953 World Cup Noise(DP)
- poj 1953 World Cup Noise DP
- poj 1953 World Cup Noise
- POJ 1953 World Cup Noise
- poj 1953 World Cup Noise
- POJ 1953 World Cup Noise
- poj 1953 World Cup Noise
- poj 1953 World Cup Noise
- POJ-1953-World Cup Noise
- poj 1953 World Cup Noise
- POJ 1953 World Cup Noise
- poj 1953:World Cup Noise
- POJ 1953World Cup Noise
- POJ 1953 World Cup Noise
- POJ 1953 World Cup Noise
- POJ 1953 World Cup Noise
- HandlerThread详解
- lintcode--数字组合
- python中去掉字符串中的空格
- js --身份证号合法性校验
- 推荐算法中的MF, PMF, BPMF
- POJ 1953 World Cup Noise(数位DP 01串)
- HTTP请求、响应报文格式
- java环境变量详解---找不到或无法加载主类
- JDBC详解
- 排列组合
- 使用批处理生成多个解决方案
- Ubuntu16桌面启动器的移动方式
- How Many Equations Can You Find HDU
- 真正的沉浸式状态栏