linruizhe111 @ 2024-08-14 00:08:18
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n,m,a[100010],dp[10010][15];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
memset(dp,0x3f,sizeof(dp));
dp[0][0]=0;
for(int j=1;j<=m;j++)
for(int i=1;i<=n;i++)
for(int k=0;k*k<=j;k++)
dp[j][i]=min(dp[j][i],dp[j-k*k][i-1]+abs(k-a[i])*abs(k-a[i]));
// for(int i=1;i<=m;i++) {
// for(int j=1;j<=n;j++)
// cout << dp[i][j]<<" ";
// cout << endl;
// }
if(dp[m][n]==0x3f)cout << "-1" << endl;
else
cout << dp[m][n];
return 0;//orz
}
by linruizhe111 @ 2024-08-14 00:08:53
到底什么时候可以用memset啊
by LiuCarry @ 2024-08-14 00:14:09
一般不太卡常时间充裕就能memset