POJ-1953 World Cup Noise(线性动规)
World Cup Noise
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 16374 Accepted: 8097
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).
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.
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
2
3
1
Sample Output
Scenario #1:
5
Scenario #2:
2
注意结果int存不下。简单的动规,递推即可
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
int n;
long long int dp[50][2];
int main()
{
int a;
while(scanf("%d",&a)!=EOF)
{
int cas=0;
while(a--)
{
memset(dp,0,sizeof(dp));
dp[1][0]=1;
dp[1][1]=1;
scanf("%d",&n);
for(int i=2;i<=n;i++)
{
dp[i][1]+=dp[i-1][0];
dp[i][0]+=(dp[i-1][0]+dp[i-1][1]);
}
printf("Scenario #%d:\n",++cas);
printf("%lld\n\n",dp[n][1]+dp[n][0]);
}
}
return 0;
}
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
World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14397 Accepted: 7129 ...
- 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 ...
- HOJ 2156 &POJ 2978 Colored stones(线性动规)
Colored stones Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1759 Accepted: 829 Descrip ...
- POJ 1953 World Cup Noise(递推)
https://vjudge.net/problem/POJ-1953 题意:输入一个n,这n位数只由0和1组成,并且不能两个1相邻.计算共有多少种排列方法. 思路:递推题. 首先a[1]=2,a[2 ...
- POJ-1958 Strange Towers of Hanoi(线性动规)
Strange Towers of Hanoi Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2677 Accepted: 17 ...
- POJ-1458 Common Subsequence(线性动规,最长公共子序列问题)
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44464 Accepted: 18186 ...
- POJ--1050--To the Max(线性动规,最大子矩阵和)
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44723 Accepted: 23679 Descript ...
随机推荐
- java痛苦学习之路[十]--日常问题汇总
FIddler2 1.FIddler2 request请求的參数出现中文乱码问题时,须要进行一下设置: 打开注冊表编辑器,找到HKCU\Software\Microsoft\Fiddler 2\,在 ...
- SpringMVC由浅入深day01_3非注解的处理器映射器和适配器
3 非注解的处理器映射器和适配器 3.1 非注解的处理器映射器 3.1.1 HandlerMapping处理器映射器 HandlerMapping 负责根据request请求找到对应的Handler ...
- ASP代码审计学习笔记 -4.命令执行漏洞
命令执行漏洞: 保存为cmd.asp,提交链接: http://localhost/cmd.asp?ip=127.0.0.1 即可执行命令 <%ip=request("ip" ...
- Cookie利用神器:CookieHacker
转自evilcos的博客 看到那么多苦逼的跨站师在问Cookie利用工具,不忍心,还是把自己写的Chrome扩展开源出来吧,功能极简,仿造<我的渗透利器>里提到的Original Cook ...
- AddChild
using UnityEngine; using UnityEngine; using UnityEditor; using System.Collections; public class AddC ...
- java 递归
package com.j1.soa.resource.cms.service.oracle; import com.j1.base.dto.ServiceMessage; import com.j1 ...
- Android开发训练之第五章——Building Apps with Connectivity & the Cloud
Building Apps with Connectivity & the Cloud These classes teach you how to connect your app to t ...
- 【线程】Thread中的join介绍
因为sleep.wait.join等阻塞,可以使用interrupted exception异常唤醒. 一.作用 Thread类中的join方法的主要作用就是同步,它可以使得线程之间的并行执行变为串行 ...
- jQuery缓存机制(一)
1.首先看一下涉及到jQuery缓存机制的代码结构: // 定义一些jQuery内部的变量,方便后续使用 var data_user, data_priv, // 后续会被赋值为两个Data对象 rb ...
- axure rp ----专业的快速原型设计工具
Axure RPAxure的发音是』Ack-sure』,RP则是』Rapid Prototyping』快速原型的缩写.Axure RP Pro是美国Axure Software Solution公司的 ...