题目链接

思路:dp,f[i]表示构成i所需要的最小步数

//swj么么哒

#include<bits/stdc++.h>
using namespace std;
int n; 
const int N = 1000000;
int f[N],mi[N];
int cnt=0;
int main() {
	cin>>n;
	int i=1;
	while(i*i<=n/i){
		mi[++cnt]=i*i*i;
		i++;
	}
	memset(f,0x3f,sizeof f);
	f[0]=0;
	for(int i=1;i<=cnt;i++) {
		for(int j=mi[i];j<=n;j++) {
			f[j]=min(f[j],f[j-mi[i]]+1);
		}
		
	}
	cout<<f[n];
}

相关文章:

  • 2021-07-20
  • 2022-01-24
  • 2021-06-26
  • 2021-11-02
  • 2021-08-11
  • 2021-07-05
  • 2021-04-03
  • 2021-06-10
猜你喜欢
  • 2021-06-18
  • 2021-07-16
  • 2022-01-11
  • 2021-10-22
  • 2021-08-11
  • 2021-09-22
  • 2021-11-23
相关资源
相似解决方案