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;
    }
  • 相关阅读:
    PL/SQL注册码
    分页sql
    js获取url值
    C语言中的bool类型 stdbool.h
    语音朗读小程序
    50. Pow(x, n)
    二维数组旋转
    用一位数组代替二维数组作为形参使用
    单链表排序——交换数据成员
    C++重载输入流、输出流运算符
  • 原文地址:https://www.cnblogs.com/moonbay/p/4555637.html
Copyright © 2011-2022 走看看