ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

*ABC 236 D - Dance(dfs)

2022-09-08 00:01:16  阅读:247  来源: 互联网

标签:ABC idx Dance LL dfs Sample Input 236 sum


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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有