POJ 1953 World Cup Noise
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 14397 | Accepted: 7129 |
Description
"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
For each scenario, you are given a single positive integer less than 45 on a line by itself.
Output
Sample Input
2
3
1
Sample Output
Scenario #1:
5 Scenario #2:
2
题目大意:求一个长度为n的由0和1组成的序列中满足没有两个1相邻的序列的数目。
解题方法:用动态规划可以很简单的解答出本题,dp方程为dp[i] = dp[i - 1] + dp[i - 2],一开始我也不明白这道题为什么是这样解答的,其实思想是这样子的,当一个长度为n - 1的01串变为长度为n的01串的时候,在后面添加一个0是没有问题的,添加一个1的组合数其实就是长度为n - 1的01串的组合数,而在后面添加一个1则必须要求长度为n - 1的01串最后一位必须为0,组合数和长度为n - 2的01串是一样的,所以dp方程为dp[i] = dp[i - 1] + dp[i - 2]。
#include <stdio.h>
#include <iostream>
using namespace std; int main()
{
int dp[] = {, , , };
int n, x, nCase;
for (int i = ; i <= ; i++)
{
dp[i] = dp[i - ] + dp[i - ];
}
scanf("%d", &n);
nCase = ;
while(n--)
{
scanf("%d", &x);
printf("Scenario #%d:\n%d\n\n", ++nCase, dp[x]);
}
return ;
}
POJ 1953 World Cup Noise的更多相关文章
- Poj 1953 World Cup Noise之解题报告
World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16369 Accepted: 8095 ...
- poj 1953 World Cup Noise (dp)
World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16774 Accepted: 8243 ...
- poj - 1953 - World Cup Noise(dp)
题意:n位长的01序列(0 < n < 45),但不能出现连续的两个1,问序列有多少种. 题目链接:id=1953" target="_blank">h ...
- POJ 1953 World Cup Noise(递推)
https://vjudge.net/problem/POJ-1953 题意:输入一个n,这n位数只由0和1组成,并且不能两个1相邻.计算共有多少种排列方法. 思路:递推题. 首先a[1]=2,a[2 ...
- POJ-1953 World Cup Noise(线性动规)
World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16374 Accepted: 8097 Desc ...
- Poj 3117 World Cup
1.Link: http://poj.org/problem?id=3117 2.Content: World Cup Time Limit: 1000MS Memory Limit: 65536 ...
- poj1953 World Cup Noise
http://poj.org/problem?id=1953 题目大意:给定一个正整数n,确定该长度的不同吟唱模式的数量,即确定不包含相邻1的n位序列的数目.例如,对于n = 3,答案是5 (序列00 ...
- POJ 1953
//FINBONACI数列 #include <iostream> #define MAXN 100 using namespace std; int _m[MAXN]; int main ...
- 【dp】 poj 1953
用n个数字0或者1组成一个排列,要求每两个1不相邻,问有多少种排法 dp[n][0]记录n个连续数,结尾为0的不同排列数dp[n][1]记录第n个连续数,结尾为1的不同排列数 DP公式: dp[i][ ...
随机推荐
- LR脚本中常用函数使用介绍
1.变量和参数的设置 //将IP地址和端口放入到参数中lr_save_string("192.168.1.133:8081","ip"); //计算变量数组的元 ...
- Python + selenium之unitest(2)
unittest单元测试框架中重要的概念: 1.Test Case 一个Test Case实例就是一个测试用例.在一个完整的测试流程中,包括测试前准备环境的搭建(setUp),实现测试过程的代码(ru ...
- sudo的用法
为了系统安全我们一般不直接使用root用户进行日常维护,sudo是临时提升root权限,有时执行一些命令或者更新没权限的文件时需要使用root,这个时候就需要sudo上场了 普通用户是没有sudo使用 ...
- POJ 2288 Islands and Bridges (状压DP,变形)
题意: 给一个无向图,n个点m条边,每个点有点权,要求找到一条哈密顿路径,使得该路径的f(path)值最大.输出f值,若有多条最大f值的路径,输出路径数量. f值由如下3点累加而来: (1)所有点权之 ...
- ceisum_加载倾斜摄影模型
osgb转换为3Dtiles格式(使用工具转换) 然后加载到cesium中(加载代码见下,可以控制模型高度) var offset = function(height,tileset) { conso ...
- mybatis association嵌套association的两级嵌套问题
今天遇到了一个双表连接查询以及自关联的问题,由于第一次遇到,所以在这记下,日后好查阅 针对一个表的关联属性本身也有自关联的情况下,可以用association嵌套association的方法来处理. ...
- 1_HDFS理论及安装部署
一.hadoop简介 1.hadoop的初衷是为了解决Nutch的海量数据爬取和存储的需要,HDFS来源于google的GFS,MapReduce来源于Google的MapReduce,HBase来源 ...
- 第四次作业:Windows各种基本应用的命令处理方法
删除文件夹命令? rd (remove directory) 如何给文件夹重新命名? ren (rename) 如何在文件夹中建立文件夹? md swift\a 如何用命令查看文本文件的内容? typ ...
- 转 Hystrix入门指南 Introduction
https://www.cnblogs.com/gaoyanqing/p/7470085.html
- Mybatis查询select 传单个参数不识别,找不到
今天, Mybatis查询select 传单个参数不识别,找不到 解决办法: 加上jdbc=varchar #{XXX,jdbc=VARCHAR}