Checking cubes.
Given a integer **N**. Find number of posiible ways to represent **N** as a sum of at most five cubes.
Given a integer N. Find number of possible ways to represent N as a sum of at most five cubes.
Input
First line contains N.
1<=N<=125000.
Output
Output the result
Example
Input: 64 Output: 2
题意:给出整数N,求将N表示为最多5个立方数的和的方案数;
题解:dp题,定义dp[i][j]为sum为i时,选j个数的方案数。
转移方程为
dp[i+k*k*k][j+1]+=dp[i][j]
注意到dp[8+1*1*1][j+1] dp[1+2*2*2][j+1]是重复的,所以要在最外层枚举k
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[125005][6];
int main(){
int n,i,j,k;
scanf("%d",&n);
dp[0][0]=1;
for(k=1;k*k*k<=n;k++){
for(i=0;i<=n-k*k*k;i++){
for(j=0;j<=4;j++){
if(dp[i][j])dp[i+k*k*k][j+1]+=dp[i][j];
}
}
}
int ans=0;
ans+=dp[n][1]+dp[n][2]+dp[n][3]+dp[n][4]+dp[n][5];
printf("%d\n",ans);
return 0;
}