This pure violence will timeout, simply push the recursive formula can be, in fact, is a Fibonacci sequence.
World Cup Noise
Time Limit: 1000MS |
|
Memory Limit: 30000K |
Total Submissions: 15937 |
|
Accepted: 7861 |
Description
Background
"Ko-re-a, ko-re-a" Shout 54.000 happy football fans after their team have reached the semifinals of the FIFA World Cup in T Heir home country. But although their excitement is real, the Korean people was still very organized by nature. For example, they has organized huge trumpets (that is, like blowing a ship's horn) to the support their team playing on th E field. The fans want to keep the level of noise constant throughout the match.
The trumpets is operated by compressed gas. However, if you blow the trumpet for 2 seconds without stopping it'll break. So when the trumpet makes noise, everything are 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 won't break, the pattern was not allowed to has a 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, 001, 010, +, 101 is acceptable while 011, a, 111 is not).
Input
The first line contains the number of scenarios.
For each scenario, you is given a single positive an integer less than in a line by itself.
Output
The output for every scenario begins with a line containing "scenario #i:", where I am the number of the scenario starting at 1. Then print a single line containing the number of n-bit sequences which has 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
1 //Oimonster2#include <cstdio>3#include <cstdlib>4#include <iostream>5 using namespacestd;6 inta[101];7 intMain () {8 inti,j,n,k;9scanf"%d",&n);Tena[0]=0; Onea[1]=2; Aa[2]=3; - for(i=3; i<= $; i++){ -a[i]=a[i-1]+a[i-2]; the } - for(i=1; i<=n;i++){ -scanf"%d",&k); -printf"Scenario #%d:\n", i); +printf"%d\n", A[k]); -printf"\ n"); + } A return 0; at}
View Code
POJ1953 World Cup Noise