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][ ...
随机推荐
- [神经网络]一步一步使用Mobile-Net完成视觉识别(四)
1.环境配置 2.数据集获取 3.训练集获取 4.训练 5.调用测试训练结果 6.代码讲解 本文是第四篇,下载预训练模型并训练自己的数据集. 前面我们配置好了labelmap,下面我们开始下载训练好的 ...
- Distinct Values(贪心)
问题 D: Distinct Values 时间限制: 1 Sec 内存限制: 128 MB提交: 13 解决: 5[提交] [状态] [讨论版] [命题人:admin] 题目描述 Chiaki ...
- Yum简单使用小结
Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器.基于RPM包管理,能够从指定的服务器自动 ...
- 解决xcode iOS真机调试正常,模拟器失败问题
今天早上遇到xcode的真机可以调试,但是模拟器却爆出一大堆错,提示错误是没有找到引用的代码文件,真机和模拟器的配置都是一样的, 准确来说,应该是除了指令以外,其他都死一样的配置,所以大概是指令配置上 ...
- 简单的Datable转List方法
public static class DataTableUtils<T> where T : new() { public static List<T> ConvertToM ...
- C/C++基础知识:函数指针和指针函数的基本概念
[函数指针] 在程序运行中,函数代码是程序的算法指令部分,它们和数组一样也占用存储空间,都有相应的地址.可以使用指针变量指向数组的首地址,也可以使用指针变量指向函数代码的首地址,指向函数代码首地址的指 ...
- POJ-1426-Find the multiply
这题深搜广搜都可以做,深搜的做法就是把每个由1 和 0 组成的数字拓展10倍以及拓展10倍+1,然后压入队列. 这样可以走过所有由10组成的数字,且两个方向平行发展(*10 +0和+1). bfs ...
- sphinx 快速使用
建立配置文件 例可以参照之前的模板新建一个配置文件 sphinx/etc目录 #MySQL数据源配置,详情请查看:http://www.coreseek.cn/products-install/mys ...
- k8s的flannel网络插件配置
flannel的网络插件配置 Kubernetes网络通信需要解决以下问题: (1)容器间通信:同一个Pod内的多个容器间的通信,lo (2)Pod通信:P ...
- Create & use FTP service on Ubuntu(在Ubuntu上搭建并使用FTP服务)
Check if the FTP service has been installed.(检查是否已安装) Vsftpd --version If it has not install,Pres ...