2019暑假多校第二场F题
登录—专业IT笔试面试备考平台_牛客网
https://ac.nowcoder.com/acm/contest/882/F
#include<iostream>#include<cstdio> #include<queue> #include<cmath> #include<algorithm> #include<set> #include<climits> #include<cstring> using namespace std; //=============struct declaration==============//=============var declaration================= const int maxn=14+10; long long a[2*maxn][2*maxn]; bool f[2*maxn];long long n,k,cnt,ans;vector<long long> q1,q2; //=============function declaration============ void dfs(long long x,long long team1n,long long team2n,long long totv); //=============main code======================= int main() { //freopen("tt.in","r",stdin); 退役OIer //freopen("tt.out","w",stdout); cin>>n; for(int i=1; i<=2*n; i++) for(int j=1; j<=2*n; j++) { cin>>a[i][j]; } dfs(1,0,0,0); cout<<ans<<endl; return 0; } //=============function code=================== void dfs(long long x,long long team1n,long long team2n,long long totv)//决定第x个人的归属,队1有team1n个人了,队2有team2n个人了,目前总竞争值为totv { if(x>2*n)//所有人都选完了 { if(totv>ans)//更新最大值 ans=totv; return; } if(team1n<n)//两种情况进队1,进队2,满了就别进了 { q1.push_back(x); vector<long long>::iterator it; long long t=0; for(it=q2.begin(); it!=q2.end(); it++)//进一个人就更新总竞争值 { t+=a[x][*it]; } dfs(x+1,team1n+1,team2n,totv+t); q1.pop_back(); } if(team2n<n) { q2.push_back(x); vector<long long>::iterator it; long long t=0; for(it=q1.begin(); it!=q1.end(); it++) { t+=a[x][*it]; } dfs(x+1,team1n,team2n+1,totv+t); q2.pop_back(); } }