費氏數列
到第 n 階的方法為第 n-1 階跨一階或第 n-2 階跨 2 階
#include <iostream>
#include <stdint.h>
using namespace std;
int main()
{
uint32_t step;
uint32_t way[10000];
way[0] = 1; way[1] = 2;
for(int32_t i = 2; i<10000; i++)
way[i] = (way[i-1] + way[i-2])%1000000007 ;
while(cin >> step)
cout << way[step-1]<< endl;
}
全站熱搜