[HDOJ6146] Pokémon GO(递推,dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6146
一个可行的思路是考虑三个子问题
-
全部走完2*N个格子的方法总数DP[N]
-
全部走完2*N个格子并且起点是最左边的两个格子之一的方法总数DP2[N]
-
全部走完2*N个格子并且起点和终点分别是最左边的两个格子的方法总数DP3[N]
组合2和3的答案就可以得到1 了。
(其实是找到了原题2333)
1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <bits/stdc++.h> 18 using namespace std; 19 #define fr first 20 #define sc second 21 #define cl clear 22 #define BUG puts("here!!!") 23 #define W(a) while(a--) 24 #define pb(a) push_back(a) 25 #define Rint(a) scanf("%d", &a) 26 #define Rll(a) scanf("%I64d", &a) 27 #define Rs(a) scanf("%s", a) 28 #define Cin(a) cin >> a 29 #define FRead() freopen("in", "r", stdin) 30 #define FWrite() freopen("out", "w", stdout) 31 #define Rep(i, len) for(int i = 0; i < (len); i++) 32 #define For(i, a, len) for(int i = (a); i < (len); i++) 33 #define Cls(a) memset((a), 0, sizeof(a)) 34 #define Clr(a, x) memset((a), (x), sizeof(a)) 35 #define Full(a) memset((a), 0x7f7f7f, sizeof(a)) 36 #define lrt rt << 1 37 #define rrt rt << 1 | 1 38 #define pi 3.14159265359 39 #define RT return 40 #define lowbit(x) x & (-x) 41 #define onenum(x) __builtin_popcount(x) 42 typedef long long LL; 43 typedef long double LD; 44 typedef unsigned long long ULL; 45 typedef pair<int, int> pii; 46 typedef pair<string, int> psi; 47 typedef pair<LL, LL> pll; 48 typedef map<string, int> msi; 49 typedef vector<int> vi; 50 typedef vector<LL> vl; 51 typedef vector<vl> vvl; 52 typedef vector<bool> vb; 53 54 const LL mod = 1e9+7; 55 const int maxn = 11000; 56 LL a[maxn], t[maxn]; 57 int n; 58 59 60 signed main() { 61 // FRead(); 62 Cls(a); Cls(t); 63 t[1] = 1; a[1] = 1, a[2] = 6; 64 For(i, 2, maxn) t[i] = (t[i-1] * 2) % mod; 65 For(i, 3, maxn) { 66 a[i] = (t[i] + (2 * a[i-1]) % mod + (4 * a[i-2]) % mod) % mod; 67 } 68 int T; 69 Rint(T); 70 W(T) { 71 Rint(n); 72 LL ret = 0; 73 ret = 4 * a[n]; 74 For(i, 2, n) { 75 ret += 8 * a[n-i] % mod * t[i-1] % mod; 76 ret += 8 * t[n-i] % mod * a[i-1] % mod; 77 ret %= mod; 78 } 79 if(n == 1) { 80 puts("2"); 81 continue; 82 } 83 printf("%I64d\n", ret); 84 } 85 RT 0; 86 }