| Run ID | Author | Problem | Lang | Verdict | Score | Time | Memory | Code Length | Submit Time |
|---|---|---|---|---|---|---|---|---|---|
| 51850 | AK2022071328 | 最优子图 | C++ | Time Limit Exceeded | 30 | 2000 MS | 3232 KB | 886 | 2022-07-14 08:17:55 |
#include <iostream> #include <cstdio> using namespace std; const int maxn=10000; int w[maxn][maxn]; int n,k; int ans=0; bool color[maxn];//1=red 0=blue void check() { int red=0; int blue=0; int a=0;//ans for(int i=0; i<n; i++) { if(color[i]) { 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])a+=w[i][j]; else a+=(k-w[i][j]); } } ans=max(ans,a); } void dfs(int num) { if(num==n) { check(); return; } else { color[num+1]=1; dfs(num+1); color[num+1]=0; dfs(num+1); } } int main() { cin>>n>>k; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { cin>>w[i][j]; } } dfs(-1); cout<<ans; return 0; }