您的位置:首页 > 其它

HDU 2563 统计问题

2015-03-31 01:42 357 查看
题意:

(中文)

思路:

一个递推问题。

定义a[i]为第i步向上走的方法,b[i]为向左或向右的方法。

f[i] = a[i] + b[i];



a[i] = a[i - 1] + b[i - 1];向上走的方法可以来源于上步向上走的和向左或向右走的。



b[i] = 2 * a[i - 1] + b[i - 1].向左或向右走的可以来源于上步向上走的两次(因为上次向上走,这次可以选两个方向),和上步向右或向左走的(只能有一种方案,因为走过的不能再走了)。

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 = 25;

LL f
;

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