题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=252
思路:第一维表示长度,第二维表示目前最后一位是0还是1
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int dp[45][2];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
dp[1][0] = dp[1][1] = 1;
for(int i=2; i<=n; i++)
{
dp[i][0] = dp[i-1][0] + dp[i-1][1];
dp[i][1] = dp[i-1][0];
}
printf("%d\n",dp[n][1] + dp[n][0]);
}
return 0;
}