题意
分析
考虑dp.
用\(d(i,j)\)表示用不超过i的立方凑成j的方案数。
\(d(i,j)=d(i-1,j)+d(i,j-i^3)\)
时间复杂度\(O(IN+T)\)
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
{
data=data*10+ch-'0';
ch=getchar();
}
return data*w;
}
template<class T>T read(T&x)
{
return x=read<T>();
}
using namespace std;
typedef long long ll;
co int I=21,N=1e4;
ll d[I+1][N+1];
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
d[0][0]=1;
for(int i=1;i<=I;++i)
for(int j=0;j<=N;++j)
{
d[i][j]=d[i-1][j];
if(i*i*i<=j)
d[i][j]+=d[i][j-i*i*i];
}
int n;
while(~scanf("%d",&n))
printf("%lld\n",d[I][n]);
return 0;
}
原文地址:https://www.cnblogs.com/autoint/p/10084374.html
时间: 2024-10-11 10:32:24