HDU 2563 统计问题
2015-03-31 01:42
357 查看
题意:
(中文)
思路:
一个递推问题。
定义a[i]为第i步向上走的方法,b[i]为向左或向右的方法。
f[i] = a[i] + b[i];
![](http://img.blog.csdn.net/20150331014516808)
a[i] = a[i - 1] + b[i - 1];向上走的方法可以来源于上步向上走的和向左或向右走的。
![](http://img.blog.csdn.net/20150331014104902)
b[i] = 2 * a[i - 1] + b[i - 1].向左或向右走的可以来源于上步向上走的两次(因为上次向上走,这次可以选两个方向),和上步向右或向左走的(只能有一种方案,因为走过的不能再走了)。
Code:
(中文)
思路:
一个递推问题。
定义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; }
相关文章推荐
- hdu 2563 统计问题
- HDU 2563 统计问题
- hdu 2563 统计问题 递推 (2 *-1,1 * -2)
- hdu 2563 统计问题
- hdu 2563 统计问题
- HDU 2563 统计问题
- [HDU 2563]统计问题[递推]
- hdu-2563-统计问题
- HDU - 2563 - 统计问题
- HDU 2563 统计问题
- HDU 2563:统计问题【数学】
- HDU 2563 统计问题 (递推)
- HDU 2563 统计问题 递推
- hdu 2563 统计问题
- HDU 2563 统计问题(递推)
- hdu 2563 统计问题
- hdu 2563 统计问题(递推)
- hdu 2563 统计问题
- HDU-2563-统计问题
- HDU 2563 统计问题(简单递推/模拟)