UVA 11137 Ingenuous Cubrency (背包水题)

这篇博客主要探讨了UVA在线判题平台上的第11137题——Ingenuous Cubrency,这是一个经典的背包问题。作者提供了详细的解题思路和可能的解决方案,帮助读者理解如何运用背包算法来求解该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2078

#include<bits/stdc++.h>
using namespace std;

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define read(x,y) scanf("%d%d",&x,&y)
#define ll long long

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
const int  maxn =1e6+5;
const int mod=1e9+7;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

ll dp[10005];
int d[100],n,tot=0;
int main()
{
    for(int i=1;i*i*i<=10000;i++) d[tot++]=i*i*i;
    while(scanf("%d",&n)!=EOF)
    {
        memset(dp,0,sizeof(dp));dp[0]=1;
        for(int i=0;i<tot;i++)
            for(int j=n;j>=0;j--)
                for(int k=1;j-k*d[i]>=0;k++) dp[j]+=dp[j-k*d[i]];
        printf("%lld\n",dp[n]);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值