19牛客多校(第二场)F Partition problem
链接:https://ac.nowcoder.com/acm/contest/882/F
来源:牛客网
来源:牛客网
时间限制:C/C++ 4秒,其他语言8秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
Given 2N people, you need to assign each of them into either red team or white team such that each team consists of exactly N people and the total competitive value is maximized.
Total competitive value is the summation of competitive value of each pair of people in different team.
The equivalent equation is ∑2Ni=1∑2Nj=i+1(vij if i-th person is not in the same team as j-th person else 0)∑i=12N∑j=i+12N(vij if i-th person is not in the same team as j-th person else 0)
输入描述:
The first line of input contains an integers N. Following 2N lines each contains 2N space-separated integers vijvij is the j-th value of the i-th line which indicates the competitive value of person i and person j. * 1≤N≤141≤N≤14 * 0≤vij≤1090≤vij≤109 * vij=vjivij=vji
输出描述:
Output one line containing an integer representing the maximum possible total competitive value.
PS:服了~~沙雕代码编辑器快吐了~
#include<bits/stdc++.h>usingnamespacestd;intar[17], br[17];intmp[30][30], n; longlongans = 0;intacnt = 0, bcnt = 0;voidgo(intpos, longlongres) {if(pos >= 2 * n) {ans = max(res, ans);return;}if(acnt < n) {ar[++acnt] = pos;longlongtmp = 0;for(inti = 1; i <= bcnt; i++) {tmp += mp[pos][br[i]];}go(pos + 1, res + tmp);--acnt;}if(bcnt < n) {br[++bcnt] = pos;longlongtmp = 0;for(inti = 1; i <= acnt; i++) {tmp += mp[pos][ar[i]];}go(pos + 1, res + tmp);--bcnt;}}intmain() {scanf("%d", &n);for(inti = 0; i < 2*n; i++) {for(intj = 0; j < 2*n; j++) {scanf("%d", &mp[i][j]);}}go(0, 0LL);printf("%lld\n", ans);return0;}/*20 1 2 31 0 4 52 4 0 63 5 6 0*/