1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #include <iostream> #include <cstdio> using namespace std; typedef long long ll; #define wfor(i,j,k) for(i=j;i<k;++i) #define mfor(i,j,k) for(i=j;i>=k;--i)
ll val[28][28]; ll sum[28]; ll res=0; ll ch[14]; ll cnt; void dfs(ll now,ll chose,ll n,ll ans)
{ if(now>=2*n) return; if(chose==n) { res=max(res,ans); return ; } ll temp=sum[now]; ll i; wfor(i,0,cnt) { temp-=val[ch[i]][now]*2; } ch[cnt++]=now; dfs(now+1,chose+1,n,ans+temp); cnt--; dfs(now+1,chose,n,ans); } int main() { std::ios::sync_with_stdio(false); #ifdef test freopen("F:\\Desktop\\question\\in.txt","r",stdin); #endif #ifdef ubuntu freopen("/home/time/debug/debug/in","r",stdin); freopen("/home/time/debug/debug/out","w",stdout); #endif ll n; cin>>n; ll i,j; wfor(i,0,2*n) { wfor(j,0,2*n) { cin>>val[i][j]; sum[i]+=val[i][j]; } } dfs(0,0,n,0); cout<<res<<endl; return 0; }
|