POJ1953 World Cup Noise

33 篇文章 0 订阅

World Cup Noise

这个题目有点类似于自动机DP,就是给定由n位组成的01序列,求不包含连续的1的序列个数。由于长度为n的字符串是有长度为n-1的字符串组成的,所以我们可以这么考虑,长度为n的字符串可以怎样从n-1的转化过来,对于以0或者1结尾的长度为n-1字符串,可以添加一个0得到以0结尾的长度为n的字符串,而不会使得序列的合法性得到破坏,如果我们要获得一个以1结尾的字符串,我们只能从以0结尾的字符串添加一个1得到,所以有num[n][0] = num[n-1][0] + num[n-1][1] , num[n][1] = num[n-1][0] ,其中num[n][0]表示长度为n的字符串以0结尾的个数,num[n][1]表示长度为n的字符串以1结尾的个数,这样我们就得到了答案,然后在程序中我们只需要预处理一下就可以了。

#include <iostream>

using namespace std ;
long long number[50][2] ;

void preprocess(){
    number[1][0] = 1 ;
    number[1][1] = 1 ;

    for(int i = 2 ; i <=45 ; i ++){
        number[i][0] = number[i-1][1] + number[i-1][0] ;
        number[i][1] = number[i-1][0] ;
    }
}

int main(){

    int t ;
    int i(0) ;
    cin>>t ;
    preprocess() ;

    while(t--){
        int x ;
        cin>>x ;
        cout<<"Scenario #"<<++i<<":"<<endl;
        cout<<number[x][0] + number[x][1] <<endl<<endl ;
    }
    return 0 ;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值