zoukankan      html  css  js  c++  java
  • hdu 1398 记忆化搜索

    题目简单,直接贴代码

    /*
    * hdu1398/win.cpp
    * Created on: 2011-10-23
    * 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 MAXV = 310;
    const int MAXK = 17;
    const int credits[] = { 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169,
    196, 225, 256, 289 };
    int dp[MAXV][MAXK];

    int dfs(int v, int k) {
    if (dp[v][k] == -1) {
    int ret = 0;
    if (k == 1) {
    ret = 1;
    } else {
    int i = 0;
    while (v >= i * credits[k - 1]) {
    ret += dfs(v - i * credits[k - 1], k - 1);
    i++;
    }
    }
    dp[v][k] = ret;
    }
    return dp[v][k];
    }

    int main() {
    #ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
    #endif
    int v;
    memset(dp, -1, sizeof(dp));
    while (scanf("%d", &v) == 1 && v > 0) {
    printf("%d\n", dfs(v, MAXK));
    }
    return 0;
    }
  • 相关阅读:
    iOS崩溃报告获取一
    GCDTimer
    Runtime
    Socket
    冒泡排序笔记
    学习java虚拟机笔记
    ftp发送文件包括中文名
    java email
    批量数据插入高效 转发
    读取本地硬盘文件,快速扫描插入 数据库
  • 原文地址:https://www.cnblogs.com/moonbay/p/2221878.html
Copyright © 2011-2022 走看看