您的位置:首页 > 其它

HDU 2190 悼念512汶川大地震遇难同胞——重建希望小学

2015-03-31 00:55 337 查看
题意:

(中文)

思路:

考虑递推:

如果第i列是以1x1结尾的,那么就只有一种情况。

如果第i列是以2x2结尾的,那么有两种情况(在上面,和在下面)。

那么公式就为:

f[i] = f[i - 1] + f[i - 2] * 2;//因为2x2的需要占用2列的位置,所以是f[i - 2]


Code:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>

#define TEST

#define LL long long
#define Mt(f, x) memset(f, x, sizeof(f));
#define rep(i, s, e) for(int i = (s); i <= (e); ++i)
#ifdef TEST
#define See(a) cout << #a << " = " << a << endl;
#define See2(a, b) cout << #a << " = " << a << ' ' << #b << " = " << b << endl;
#define debug(a, s, e) rep(_i, s, e) {cout << a[_i] << ' ';} cout << endl;
#define debug2(a, s, e, ss, ee) rep(i_, s, e) {debug(a[i_], ss, ee)}
#else
#define See(a)
#define See2(a, b)
#define debug(a, s, e)
#define debug2(a, s, e, ss, ee)
#endif // TEST

const int MAX = 2e9;
const int MIN = -2e9;
const double eps = 1e-8;
const double PI = acos(-1.0);

using namespace std;

const int N = 35;

LL f
;

int main()
{
f[1] = 1;
f[2] = 3;
for(int i = 3; i <= 30; ++i)
{
f[i] = f[i - 1] + 2 * f[i - 2];
}
int T;
cin >> T;
while(T--)
{
int n;
scanf("%d", &n);
printf("%lld\n", f
);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: