其他分享
首页 > 其他分享> > *ABC 236 D - Dance(dfs)

*ABC 236 D - Dance(dfs)

作者:互联网

https://atcoder.jp/contests/abc236/tasks/abc236_d

题意:两个两个组队,开心值异或,求最大开心值。

注意这句话:
If Person i and Person j pair up, where i is smaller than j。
Sample Input 1  
2
4 0 1
5 3
2
Sample Output 1  
6
 
Sample Input 2  
1
5
Sample Output 2  
5 

Sample Input 3  
5
900606388 317329110 665451442 1045743214 260775845 726039763 57365372 741277060 944347467
369646735 642395945 599952146 86221147 523579390 591944369 911198494 695097136
138172503 571268336 111747377 595746631 934427285 840101927 757856472
655483844 580613112 445614713 607825444 252585196 725229185
827291247 105489451 58628521 1032791417 152042357
919691140 703307785 100772330 370415195
666350287 691977663 987658020
1039679956 218233643
70938785
Sample Output 3  
1073289207
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=200200,M=2002;
LL n,maxn=0,sum=0;
LL a[M][M];
LL vis[N];
void dfs(LL idx,LL sum)
{
    if(idx>(2*n-1))//总共有(2*n-1)*(2*n-1)个数字,对数即为(2*n-1)
    {
        maxn=max(maxn,sum);
        return ;
    }
    if(vis[idx])
    {
        dfs(idx+1,sum);
        return ;
    }
    for(LL i=idx+1;i<=2*n;i++)
    {
        if(!vis[i])
        {
            vis[i]=1;
            dfs(idx+1,sum^a[idx][i]);
            vis[i]=0;
        }
    }
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)
    {
        cin>>n;
        for(LL i=1;i<=2*n-1;i++)
            for(LL j=i+1;j<=2*n;j++)
            cin>>a[i][j];
        dfs(1,0);//0跟任何数字异或都是那个数字
        cout<<maxn<<endl;
    }
    return 0;
}

标签:ABC,idx,Dance,LL,dfs,Sample,Input,236,sum
来源: https://www.cnblogs.com/Vivian-0918/p/16667769.html