SPOJ BOKAM143SOU dp

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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值