poj-1953

该博客探讨了POJ-1953题目的解决方案,即世界杯比赛中球迷使用压缩气体操作的喇叭支持球队,需要保持噪音水平恒定,且不能连续吹响2秒导致喇叭损坏。博主提出了一种动态规划的思路,通过计算不同长度没有相邻1的比特序列数量来解决此问题。文章包含了问题描述、解题思路和代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

链接:http://poj.org/problem?id=1953

题目:

World Cup Noise

Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 19394 Accepted: 9258

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

思路:

有n位数时 1.当开头为1时后面必为0因此有f(n-2)种可能 2.当开头为0时后面就有f(n-1)种可能

因此 f(n) = f(n-1)+f(n-2)

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long int ll;
ll fei[46];
void feibo()
{
    fei[1]=2;
    fei[2]=3;
    for(int i=3;i<=45;i++)
        fei[i] = fei[i-1]+fei[i-2];
}
int main()
{
    feibo();
    int t,n;
    scanf("%d",&t);
    for(int tt=1;tt<=t;tt++)
    {
        scanf("%d",&n);
        printf("Scenario #%d:\n%lld\n\n",tt,fei[n]);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值