【UVA】11137-Ingenuous Cubrency

DP问题,须要打表。

dp[i][j]代表利用大小不超过i的数字组成j的方法。

状态方程是 dp[i][j] = d[i - 1][j] + sum{dp[i - 1][j - k * i * i *i]};

14327705 11137 Ingenuous Cubrency Accepted C++ 0.049 2014-10-09 10:20:48

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 11111;
const int maxd = 10000;
LL dp[40][maxn];
void List(){
    memset(dp,0,sizeof(dp));
    for(int i = 1 ; i <= maxd ; i++) dp[1][i] = 1;
    for(int i = 2 ; i * i * i <= maxd ; i ++){
        for(int j = 1; j <= maxd ; j ++){
            dp[i][j] += dp[i - 1][j];
            for(int k = 1; ; k ++){
                if(j - k * i * i * i > 0)
                    dp[i][j] += dp[i - 1][j - k * i * i * i];
                else if(j - k * i * i * i == 0)
                    dp[i][j] ++;
                else
                    break;
            }
        }
    }
}
int main(){
    List();
    int n,k;
    for(k = 1; k * k * k <= maxd ; k ++);
    while(scanf("%d",&n) != EOF){
        printf("%lld\n",dp[k - 1][n]);
    }
    return 0;
}
时间: 2024-08-24 07:35:50

【UVA】11137-Ingenuous Cubrency的相关文章

uva 11137 Ingenuous Cubrency (完全背包)

uva 11137 Ingenuous Cubrency People in Cubeland use cubic coins. Not only the unit of currency is called a cube but also the coins are shaped like cubes and their values are cubes. Coins with values of all cubic numbers up to 9261 (= 21 3), i.e., coi

【UVA】12034-Race(递推,组合数打表)

递推公式,假设第一名有i个人并列,那么: f[n] = C(n,i) * f[n - i]; 打出1 ~ 1000的所有组合数,之后记忆化搜索,需要打表. 14026995 12034 Race Accepted C++ 0.032 2014-08-12 11:47:47 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector&g

【UVA】10285-Longest Run on a Snowboard(动态规划)

这题出简单了,不需要打印路径. 状态方程dp[i][j] = max(dp[i-1][j],dp[i][j-1],dp[i+1][j],dp[i][j+1]); 14003395 10285 Longest Run on a Snowboard Accepted C++ 0.026 2014-08-07 11:43:51 枚举每个点进行遍历,使用记忆化搜索.要不会超时. #include<cstdio> #include<cstring> #include<iostream&

【UVA】434-Matty&amp;#39;s Blocks

一道非常easy想复杂的题,给出主视图和右视图,计算最少能用几个正方体组成相应的视图,以及最多还能加几块正方体. 求最多加入事实上就是求出最多的正方体数减去最少的,主要就是最少的不好求. 一開始各种模拟就是不正确,之后发现,仅仅须要统计两个视图的高度个数就能够了(简直了) 14390495 434 Matty's Blocks Accepted C++ 0.016 2014-10-21 11:35:11 #include<cstdio> #include<cstring> #inc

【UVA】434-Matty&#39;s Blocks

一道很容易想复杂的题,给出主视图和右视图,计算最少能用几个正方体组成对应的视图,以及最多还能加几块正方体. 求最多添加其实就是求出最多的正方体数减去最少的,主要就是最少的不好求. 一开始各种模拟就是不对,之后发现,只需要统计两个视图的高度个数就可以了(简直了) 14390495 434 Matty's Blocks Accepted C++ 0.016 2014-10-21 11:35:11 #include<cstdio> #include<cstring> #include&l

【UVA】12169-Disgruntled Judge(暴力or欧几里得)

可能由于后台数据的原因,这道题直接暴力枚举a,b进行判断也能过,不过跑的时间长,效率太差了. 14021006 12169 Disgruntled Judge Accepted C++ 0.876 2014-08-11 08:46:28 不说了,比较无脑. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #incl

【UVa】Headmaster&#39;s Headache(状压dp)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1758 晕....状压没考虑循环方向然后错了好久.. 这点要注意...(其实就是01背包变成了完全背包QAQ 我们将课程拆成两个点,然后状压 那么答案就是(1<<(s<<1))-1 转移就不说了,,,,,太简单.. #include <cstdio> #in

【UVA】1210 - Sum of Consecutive Prime Numbers

普通的求区间连续和的问题,一开始以为是区间移动,但是怕UVA数据太严,直接打表,后来发现自己的担心是多余的. 14044972 1210 Sum of Consecutive Prime Numbers Accepted C++ 0.049 2014-08-15 10:30:11 打表的话效率可能不是很高. AC代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm&

【UVA】815 - Flooded!

水题,排序之后依次累加,模拟. 14069284 815 Flooded! Accepted C++ 0.032 2014-08-20 10:42:17 AC代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #includ