提交时间:2023-12-16 10:10:21

运行 ID: 116303

#include<bits/stdc++.h> #define int long long using namespace std; int dp[114514],a[105]; signed main(){ int n; cin>>n; for (int i = 0;i <= 101;i++){ a[i] = i * i; } memset(dp,0x7f7f7f7f,sizeof(dp)); dp[0] = 0; //cout<<"-0\n"; for (int i = 1;i <= n;i++){ for (int j = 100;j >= 0;j--){ //cout<<i<<' '<<j<<'\n'; if (i >= a[j]){ dp[i] = min(dp[i],dp[i - a[j]] + 1); } } } cout<<dp[n]; return 0; }