提交时间:2022-07-13 11:50:23
运行 ID: 51522
#include<cstdio> #include<algorithm> #include<queue> using namespace std; typedef long long ll; const int N=66; int n; ll k; ll a[N][N],ans; int b[N]; ll tj() { ll ret=0; bool chk=1; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { if(b[i]!=b[j]) ret+=(k-a[i][j]),chk=0; else ret+=a[i][j]; } if(chk) return 0; return ret; } void dfs(int now) { if(now==n+1) { ans=max(ans,tj()); return ; } b[now]=1; dfs(now+1); b[now]=2; dfs(now+1); } struct data{ int id; ll num,sum; }; int main() { scanf("%d %lld",&n,&k); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%lld",&a[i][j]); if(n<=20) { dfs(1); printf("%lld\n",ans); } else { printf("%d\n",n*(n-1)/2); } }