19牛客多校(第二场)F Partition problem

链接:https://ac.nowcoder.com/acm/contest/882/F
来源:牛客网
时间限制:C/C++ 4秒,其他语言8秒
空间限制: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=12Nj=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.
* 1N141≤N≤14 * 0vij1090≤vij≤109 * vij=vjivij=vji

输出描述:

Output one line containing an integer representing the maximum possible total competitive value.
示例1

输入

复制
1
0 3
3 0

输出

复制
3

这道题快把我做she了。。。。C(14,28)的值4e7左右,他的时限是在4秒左右,直接暴力跑所有情况是能跑完的。

但是如果每种情况都要n*n的暴力求总竞争值,那么会超时:复杂度多了。这种情况下我们可以看出来,在递归过程中下一次状态的竞争值和上一个状态的值差的就是加上某个点之后的变化。。所以我们可以通过一些操作来减少一些复杂度的。~就酱~~

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;
}
/*
2
0 1 2 3
1 0 4 5
2 4 0 6
3 5 6 0
 
*/

全部评论
牛客的代码编辑太傻了,等我们更新编辑器
点赞 回复 分享
发布于 2019-07-21 16:09

相关推荐

找工作勤劳小蜜蜂:自我描述部分太差,完全看不出想从事什么行业什么岗位,也看不出想在哪个地区发展,这样 会让HR很犹豫,从而把你简历否决掉。现在企业都很注重员工稳定性和专注性,特别对于热爱本行业的员工。 你实习的工作又太传统的it开发(老旧),这部分公司已经趋于被淘汰,新兴的互联网服务业,比如物流,电商,新传媒,游戏开发和传统的It开发有天然区别。不是说传统It开发不行,而是就业岗位太少,基本趋于饱和,很多老骨头还能坚持,不需要新血液。 工作区域(比如长三角,珠三角,成渝)等也是HR考虑的因素之一,也是要你有个坚定的决心。否则去几天,人跑了,HR会被用人单位骂死。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务