poj 1953 World Cup Noise

#include <iostream>            //斐波那契数列
using namespace std;
int main()
{
int fib[50]={1,2},c,n,i;
for(i=2;i<45;++i)
fib[i]
=fib[i-1]+fib[i-2];
cin
>>c;
for(i=1;i<=c;++i)
{
cin
>>n;
cout
<<"Scenario #"<<i<<":\n"<<fib[n]<<endl<<endl;
}
return 0;
}

//对于这样一个0,1序列,a1,a2,a3,...a(i-2),a(i-1),a(i)...
//设f(i)为输入的数对应的结果
//则(1)a(i)=0,对a(i-1)无影响,f(i)=a(i-1)
//(2) a(i)=1,a(i-1)只能取0,则对a(i-2)无影响,f(i)=a(i-2)
//故f[i]=f[i-1]+f[i-2];

  

posted on 2011-07-22 14:55  sysu_mjc  阅读(81)  评论(0编辑  收藏  举报

导航