提交时间:2022-07-13 11:51:24
运行 ID: 51536
#include<cstdio> #include<iostream> #define int long long using namespace std; int n,k,a[551][551],sum,ans=1145141145141919; signed main() { scanf("%lld%lld",&n,&k); if(n>20) { printf("%lld",(n-1)*(n-1)); return 0; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { scanf("%lld",&a[i][j]); sum+=a[i][j]; a[i][j]=a[i][j]-(k-a[i][j]); } sum>>=1; for(int i=1;i<=(1<<(n-1));i++) { int ff=0; for(int j=1;j<=n;j++) { if(i&(1<<(j-1))) { for(int k=1;k<=n;k++) if(!(i&(1<<(k-1))))ff+=a[j][k]; } } ans=ans<ff?ans:ff; } printf("%lld",sum-ans); return 0; }