您的位置:首页 > 其它

递推DP URAL 1225 Flags

2015-05-06 17:37 399 查看
题目传送门

 /*
1 r; 2 b; 3 w
2不能在最前面,所以dp[1] = 2;    dp[2] = 2: 13 or 31

dp[i] = dp[i-1] + dp[i-2];
只加1或3时,总数dp[i-1];    只加12或32时,总数dp[i-2];
详细解释:http://www.cnblogs.com/vongang/archive/2011/09/30/2196847.html
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAXN = 55;
const int INF = 0x3f3f3f3f;
long long dp[MAXN];

int main(void)        //URAL 1225 Flags
{
//freopen ("A.in", "r", stdin);

int n;
while (scanf ("%d", &n) == 1)
{
memset (dp, 0, sizeof (dp));

dp[1] = 2;    dp[2] = 2;
for (int i=3; i<=n; ++i)
{
dp[i] = dp[i-1] + dp[i-2];
}

printf ("%I64d\n", dp
);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: