zoukankan      html  css  js  c++  java
  • UVa 10450

    题目:构造一个01串,使得当中的1不相邻,问长度为n的串有多少中。

    分析:数学,递推数列。

                设长度为n的串有n个。则有递推关系:f(n)= f(n-1)+ f(n-2);

                长度为n的结束可能是0或者1:

                假设结束是0。则前面是0或者是1都能够所以是f(n-1)。

                假设结束是1,则前面的必定是0,则更前面的任意,所以是f(n-2);

                这显然是Fib的递推公式,f(n)= Fib(n+1)。

    说明:用long long防止溢出。

    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    long long Fib[100];
    
    int main()
    {
    	Fib[1] = Fib[0] = 1LL;
    	for (int i = 2 ; i < 55 ; ++ i)
    		Fib[i] = Fib[i-1]+Fib[i-2];
    	
    	int n,m;
    	while (cin >> n) 
    	for (int i = 1 ; i <= n ; ++ i) {
    		cin >> m;
    		cout << "Scenario #" << i << ":
    " << Fib[m+1] << "
    
    ";
    	}
    		
    	return 0;
    }
    

  • 相关阅读:
    sss
    stm32cube使用
    FreeRTOS
    嵌入式网站
    CRC分段校验
    IAR编译器
    (转)UCOSII源代码剖析
    (转)stm32硬件IIC
    keil MDK注意事项
    (转).Net中自定义类作为Dictionary的key详解
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/6733314.html
Copyright © 2011-2022 走看看