提交时间:2022-07-13 11:53:44
运行 ID: 51579
#include<cstdio> #define rep(a,b,c) for(int c(a);c<=(b);++c) inline int read() { int res=0;char ch=getchar();while(ch<'0'||ch>'9')ch=getchar(); while(ch<='9'&&ch>='0')res=res*10+(ch^48),ch=getchar();return res; } template<typename T> inline T min(const T&x,const T&y){return x<y?x:y;} template<typename T> inline T max(const T&x,const T&y){return x<y?y:x;} typedef long long LL;const int N=510;int n,w[N][N],K; inline LL FF(int i){return i*(i-1)/2;} namespace Sub1 { LL ans=0;bool vis[N]; inline void dfs(int p=1,LL res=0) { if(p==n+1) { bool f[2]={false,false}; rep(1,n,i)f[vis[i]]=true; if(f[0]&&f[1])ans=max(ans,res); // rep(1,n,i)printf("%d",vis[i]);printf(" :: %d\n",res); return; } vis[p]=true;LL tmp=0;for(int i=1;i<p;++i){tmp+=vis[i]?w[p][i]:K-w[p][i];} dfs(p+1,res+tmp); vis[p]=false; tmp=0;for(int i=1;i<p;++i){tmp+=vis[i]?K-w[p][i]:w[p][i];} dfs(p+1,res+tmp); } inline void mian(){dfs();printf("%lld\n",ans);return;} } int main() { n=read();K=read();rep(1,n,i)rep(1,n,j)w[i][j]=read(); if(K==1) { LL ans=0;for(int i=1;i<n;++i){ans=max(ans,FF(i)+FF(n-i));} printf("%lld\n",ans);return 0; } if(n<=20)return Sub1::mian(),0; }