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][ ...
随机推荐
- Python+selenium之下载文件
一.Firefox文件下载 Web容许我们设置默认的文件下载路劲,文件会自动下载并且存放在指定的目录下. from selenium import webdriver import os fp = w ...
- javaSe-常用的类之Calender
Calendar是java中常用的类,比data类使用更加方便,更能更加强大,好吧多的不用你说了,直接上代码 import java.util.Calendar;//需要引进的包 public cla ...
- 不写画面的网页程序设计,Web API、Web Service、WCF Service
客户有一个系统,经常要连上我方,查询数据 以前的作法是给对方一个账号,让他可以连上我们的DB来查询. 所以,早期的同仁,真的给他们DB链接字符串 客户的Windows程序.网站就真的靠这么危险的方式, ...
- TIF转JPG
public void TifToJpg(string tifPath, string tifName) { try { //找到后缀为TIF的图像,如果没有,就catch退出 int len = t ...
- python 基础之for循环有限循环
# range(3) 表示 >>> range(3) [0, 1, 2] for循环 for i in range(3): print(i) 测试 0 1 2 打印1~100的奇数 ...
- 2019全套Java视频 免费赠送
本人今年刚看完这套课程找到工作了 待遇还不错 现在送给大家 网盘链接:https://pan.baidu.com/s/1cEK6WoXS4F9SRgj1bZclqg提取码:bjl8希望对大家有用 一起 ...
- JAVA并发编程:相关概念及VOLATILE关键字解析
一.内存模型的相关概念 由于计算机在执行程序时都是在CPU中运行,临时数据存在主存即物理内存,数据的读取和写入都要和内存交互,CPU的运行速度远远快于内存,会大大降低程序执行的速度,于是就有了高速缓存 ...
- 用Python计算最长公共子序列和最长公共子串
如何用Python计算最长公共子序列和最长公共子串 1. 什么是最长公共子序列?什么是最长公共子串? 1.1. 最长公共子序列(Longest-Common-Subsequences,LCS) 最长公 ...
- python 函数内使用全局变量
x = def change_global(): global x x = x + change_global() print(x) result: 2
- Bootstrap历练实例:标签修饰
您可以使用修饰的 class label-default.label-primary.label-success.label-info.label-warning.label-danger 来改变标签 ...