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., coins with the denominations of 1, 8, 27, …, up to 9261 cubes, are available in Cubeland.

Your task is to count the number of ways to pay a given amount using cubic coins of Cubeland. For example, there are 3 ways to pay 21 cubes: twenty one 1 cube coins, or one 8 cube coin and thirteen 1 cube coins, or two 8 cube coin and five 1 cube coins.

Input consists of lines each containing an integer amount to be paid. You may assume that all the amounts are positive and less than 10000.

For each of the given amounts to be paid output one line containing a single integer representing the number of ways to pay the given amount using the coins available in Cubeland.

Sample input

10

21

77

9999

Output for sample input

2

3

22

440022018293

题目大意:有21种硬币(1~21的三次方),给出一个金额数,求用21种硬币可以组成该金额数的方法数。

解题思路:完全背包。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#define N 10005
using namespace std;
typedef long long ll;
ll coin[21] = {1, 8, 27, 64, 125, 216, 343, 512, 729, 1000, 1331, 1728, 2197, 2744, 3375, 4096, 4913, 5832, 6859, 8000, 9261};
ll dp[10005];
int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        memset(dp, 0, sizeof(dp));
        dp[0] = 1;
        for (int i = 0; i < 21; i++) {
            for (int j = coin[i]; j <= n; j++) {
                if (dp[j - coin[i]]) {
                    dp[j] += dp[j - coin[i]];
                }
            }
        }
        printf("%lld\n", dp[n]);
    }
    return 0;
}
时间: 2024-12-13 14:16:58

uva 11137 Ingenuous Cubrency (完全背包)的相关文章

UVA - 11137 Ingenuous Cubrency[背包DP]

People in Cubeland use cubic coins. Not only the unit of currency iscalled a cube but also the coins are shaped like cubes and their valuesare cubes. Coins with values of all cubic numbers up to 9261(= 213),i.e., coins with the denominations of 1, 8,

UVa 11137 - Ingenuous Cubrency

题目:统计一个数字可以有多少种立方和的表示方式. 分析:dp,完全背包.又见整数拆分. 说明:csdn冲进前1000了,(*^__^*) 嘻嘻--. #include <iostream> #include <cstdlib> #include <cstring> using namespace std; int cube[25]; long long F[10001]; int main() { for (int i = 0 ; i <= 21 ; ++ i)

【Java】【滚动数组】【动态规划】UVA - 11137 - Ingenuous Cubrency

滚动数组优化自己画一下就明白了. http://blog.csdn.net/u014800748/article/details/45849217 解题思路:本题利用递推关系解决.建立一个多段图,定义状态d(i,j)表示"使用不超过i的整数的立方,累加和为j"的方案数.那么根据加法原理,如果没有选择数字i的立方和就得到了j,那么方案数就是d(i-1,j):如果选择了数字i的立方和才得到了j,那么方案数是d(i,j-i^3).即: d(i,j)=d(i-1,j)+d(i,j-i^3);

【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> #inc

uva11137Ingenuous Cubrency(完全背包)

题目:Ingenuous Cubrency 题目大意:给出一类钱,面值有1, 8, 27... (21)^3这21种,然后给出N,问N可以有多少组成方式. 解题思路:dp[i]代表面值为i的最多有多少种组合方式,状态转移方程:dp[i] += dp[i - value[1...21]].  如果要组成i值的话,那么它一定是由之前的状态(i - value[j])加上现有的面值组成.所以只要遍历一边面值,将之前的状态找出来,然后累加起来就可以了.这里可以用递推,因为状态的计算顺序是知道的. 代码:

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA - 10163Storage Keepers(01背包)

题目大意:UVA - 10163Storage Keepers(01背包) 题目大意:现在有m个守店人,和n家店,每个守店人有个能力值,然后一个守护店的人可以守K家店,那么这些店能到的安全度就是Pi / K.店的安全度取决于守护它的人给的安全度中间最低的那个.这些店的最高安全度取决于最低安全度的那家店.现在问如何雇佣这些人使得店的安全度最高的情况下,费用最少. 解题思路: 安全度要求最高,那么就是要判断每个守店的人要不要雇佣,并且雇佣来之后让它守几家店(安全度).dp[i][j]表示:前面的i家

UVA - 10313Pay the Price(完全背包)

题目:UVA - 10313Pay the Price(完全背包) 题目大意:同样是凑钱的问题,只是询问的时候是要按照凑钱用的硬币个数的范围来做统计的. 解题思路:这里零钱1--300,固定的.并且查询的N也是最大300,那么凑N最多的硬币个数就是N了,这里给定p,q说小于1100,所以只要大于300的就可以不用计算了,一定是0个.dp[i][j]: 用j个硬币凑足i的种数.并且零钱是固定的,所以可以一开始就将1 -- 300的dp[N][1..N]求出来,之后就直接查询.注意这里的N 可以等于

UVa 11137 (完全背包方案数) Ingenuous Cubrency

题意:用13.23……k3这些数加起来组成n,输出总方案数 d(i, j)表示前i个数构成j的方案数则有 d(i, j) = d(i-1, j) + d(i, j - i3) 可以像01背包那样用滚动数组来实现 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 using namespace std; 6 7 const int maxn = 10; 8