zoukankan      html  css  js  c++  java
  • bjfu1332 简单动规

    挺简单的动态规划题。我用记忆化搜索打的。直接上代码:

    /*
     * 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;
    typedef long long LL;
    const int card[53] = {0, 1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13};
    int ans[53][60];
    int dfs(int m, int n) {
        if (n == 0) {
            return 1;
        }
        if (m == 0) {
            return 0;
        }
        if (ans[m][n] > -1) {
            return ans[m][n];
        }
        if (card[m] > n) {
            ans[m][n] = dfs(m - 1, n);
        } else {
            ans[m][n] = dfs(m - 1, n - card[m]) + dfs(m - 1, n);
        }
        return ans[m][n];
    }
    
    int main() {
        int T, n;
        scanf("%d", &T);
        memset(ans, -1, sizeof(ans));
        while (T--) {
            scanf("%d", &n);
            printf("%d
    ", dfs(52, n));
        }
        return 0;
    }
  • 相关阅读:
    项目ITP(五) spring4.0 整合 Quartz 实现任务调度
    [Git 系列] WIN7下Git的安装
    Candy
    OSGI
    JAVA编程思想(1)
    [python] 字典和列表中的pop()函数
    R语言编程语法
    Linux 之创建工作目录-mkdir
    python 之 改变工作目录
    python 之 'and' 和 'or'
  • 原文地址:https://www.cnblogs.com/moonbay/p/4555637.html
Copyright © 2011-2022 走看看