您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: