zoukankan      html  css  js  c++  java
  • hdu 2151 DP

    很简单的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;
    }
  • 相关阅读:
    【leetcode】反转字符串
    【leetcode】反转字符串 II
    053-669
    053-668
    053-667
    053-666
    053-665
    053-664
    053-663
    053-662
  • 原文地址:https://www.cnblogs.com/moonbay/p/2751633.html
Copyright © 2011-2022 走看看