题意:
n<=28个人,分成人数相同的两组,给你2*n*2*n的矩阵,如果(i,j)在不同的组里,竞争力增加v[i][j],问你怎么分配竞争力最
4s
思路:
枚举C(28,14)的状态,更新答案即可
代码:
#include<iostream> #include<cstdio> #include<algorithm> //#include<cmath> #include<cstring> #include<string> #include<stack> #include<queue> #include<deque> #include<set> #include<vector> #include<map> #define fst first #define sc second #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define lc root<<1 #define rc root<<1|1 using namespace std; typedef double db; typedef long double ldb; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> PI; typedef pair<ll,ll> PLL; const db eps = 1e-6; const int mod = 1e9+7; const int maxn = 1e6+100; const int maxm = 2e6+100; const int inf = 0x3f3f3f3f; //const db pi = acos(-1.0); int n; ll v[111][111]; ll ans; ll tmp; int cnt0,cnt1; int v0[maxn],v1[maxn]; int m; void dfs(int x, int y){//p / num of need 1 ll now=0; if(x==m+1){ans=max(ans,tmp);return;} if(m-x>=y){ v0[++cnt0]=x; for(int i = 1; i <= cnt1; i++)now+=v[v1[i]][x]; tmp+=now; dfs(x+1,y); tmp-=now; cnt0--; } if(y>0){ now=0; v1[++cnt1]=x; for(int i = 1; i <= cnt0; i++)now+=v[v0[i]][x]; tmp+=now; dfs(x+1,y-1); tmp-=now; cnt1--; } return; } int main(){ scanf("%d", &n); m = 2*n; ans=tmp=0; cnt0=cnt1=0; for(int i = 1; i <= m; i++){ for(int j = 1; j <= m; j++){ scanf("%d", &v[i][j]); } } dfs(1,n); printf("%lld",ans); return 0; } /* 2 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 */