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;
    }
  • 相关阅读:
    关于相对定位与绝对定位
    一些常用但不平凡的CSS属性
    Java-认识变量、注释并能及时发现错误
    了解Java并学会创建Java项目(一个菜鸟的成长历程)
    竞态条件
    web服务器原理
    信号
    静态网页与动态网页区别
    mmap
    HTTP协议
  • 原文地址:https://www.cnblogs.com/moonbay/p/4555637.html
Copyright © 2011-2022 走看看