nyoj 01串(dp)
开始做DP。。
第n位为0时,dp[n] = dp[n-1]
第n位为1时,dp[n] =dp[n-2]
得公式dp[n] = dp[n-1] + dp[n-2];
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<string> 6 #include<queue> 7 #include<algorithm> 8 #include<map> 9 #include<iomanip> 10 #include<climits> 11 #include<string.h> 12 #include<cmath> 13 #include<stdlib.h> 14 #include<vector> 15 #include<stack> 16 #include<set> 17 #define INF 1e7 18 #define MAXN 100010 19 #define maxn 1000010 20 #define Mod 1000007 21 #define N 1010 22 using namespace std; 23 typedef long long LL; 24 25 int T, n; 26 int dp[111]; 27 28 void run() 29 { 30 cin >> n; 31 memset(dp, 0, sizeof(dp)); 32 dp[2] = 3, dp[3] = 5; 33 for (int i = 4; i < 110; ++i) 34 dp[i] = dp[i - 1] + dp[i - 2]; 35 cout << dp[n] << endl; 36 } 37 38 int main() 39 { 40 cin >> T; 41 while (T--) 42 run(); 43 //system("pause"); 44 return 0; 45 }