提交时间:2022-07-13 11:55:56
运行 ID: 51603
#include <bits/stdc++.h> using namespace std; int n,k; int a[10000][10000]; bool color[100000]; int red,blue,maxans,ans; void go() { red = 0,blue = 0,ans = 0; for(int i=0; i<n; i++) { if(color[i] == 1)red++; else blue++; } if(red == 0 || blue == 0) return; for(int i=0; i<n; i++) for(int j=i; j<n; j++) { if(color[i] == color[j]) ans += a[i][j]; else ans += (k-a[i][j]); } maxans = max(ans,maxans); } void dfs(int a) { if(a == n) { go(); return; } else { color[a+1] = 1; dfs(a+1); color[a+1] = 0; dfs(a+1); } } int main() { cin >> n >> k; for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin >> a[i][j]; dfs(0); cout << maxans <<endl; return 0; }