标签:
dp[i] = dp[i-1] + dp[i-2] 从第i-1阶跨1级上到第i阶 + 从第i-2阶跨2级上到第i阶
#include <iostream> #include <cstdio> using namespace std; int dp[50]; int main() { dp[2] = 1; dp[3] = 2; for( int i = 4; i <= 50; i++ ) dp[i] = dp[i-1] + dp[i-2]; int cas, n; scanf( "%d", &cas ); while( cas-- ) { scanf( "%d", &n ); printf( "%d\n", dp[n] ); } return 0; }
标签:
原文地址:http://www.cnblogs.com/fengxy/p/4792902.html