hdu 2151 DP
2012-11-02 17:34
267 查看
很简单的DP,我用记忆化搜索打的~~
/* * hdu2151/win.cpp * Created on: 2012-11-2 * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> #include <stack> #include <string> #include <vector> #include <deque> #include <list> #include <functional> #include <numeric> #include <cctype> using namespace std; const int MAXN = 105; const int MAXM = 105; int dp[MAXN][MAXM]; int N, P; int dfs(int t, int m) { if(dp[t][m] >= 0) { return dp[t][m]; } if(m == 0) { dp[t][m] = (t == P ? 1 : 0); return dp[t][m]; } dp[t][m] = 0; if(t > 1) { dp[t][m] += dfs(t - 1, m - 1); } if(t < N) { dp[t][m] += dfs(t + 1, m - 1); } return dp[t][m]; } int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif int m, t; while(scanf("%d%d%d%d", &N, &P, &m, &t) == 4) { fill_n(*dp, MAXN * MAXM, -1); printf("%d\n", dfs(t, m)); } return 0; }
相关文章推荐
- hdu 2151 DP
- 状态树hdu 2151(DP)
- HDU 2151:Worm【dp】
- hdu 2151 简单dp
- hdu 2151 Worm (DP)
- hdu_2151 worm ( 简单DP )
- hdu 2151 Worm (DP)
- hdu 2151 Worm (DP)
- HDU 2602 Bone Collector(01背包,DP)
- HDU 4258 Covered Walkway【斜率优化dp】
- hdu1978——How many ways(记忆化dp)
- hdu 5067 Harry And Dig Machine (状态压缩dp)
- HDU 2154 跳舞毯 | DP | 递推 | 规律
- hdu 1003 递归(DP)
- HDU 1074 Doing Homework (状态压缩DP)
- hdu 2476 String painter 区间dp
- hdu 5067 状态dp
- hdu_3001_Travelling(状压DP)
- HDU 2859 简单DP
- HDU 1074 Doing Homework (二进制状态压缩,状压dp)