zoukankan      html  css  js  c++  java
  • codeforces193B

    CF193B Xor

    sol:发现好像非常不可做的样子,发现n,u都很小,大胆dfs,因为异或偶数次毫无卵用,只要判每次是否做2操作就是了,复杂度O(可过)

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    inline ll read()
    {
        ll s=0; bool f=0; char ch=' ';
        while(!isdigit(ch))    {f|=(ch=='-'); ch=getchar();}
        while(isdigit(ch)) {s=(s<<3)+(s<<1)+(ch^48); ch=getchar();}
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0) {putchar('-'); x=-x;}
        if(x<10) {putchar(x+'0'); return;}
        write(x/10); putchar((x%10)+'0');
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=35;
    const ll inf=0x7fffffffffll;
    int n,m,r;
    ll ans,a[N],b[N],k[N],p[N];
    inline ll calc(ll num[])
    {
        int i;
        ll res=0;
        for(i=1;i<=n;i++) res+=1LL*num[i]*k[i];
        return res;
    }
    inline void dfs(ll num[],int step)
    {
        if(step==0)
        {
            ans=max(ans,calc(num)); return;
        }
        int i;
        ll c[N],d[N];
        for(i=1;i<=n;i++) c[i]=num[i]^b[i];
        if(step&1) ans=max(ans,calc(c)); else ans=max(ans,calc(num));
        for(i=1;i<=n;i++) d[i]=num[p[i]]+r;
        dfs(d,step-1);
        if(step<2) return;
        for(i=1;i<=n;i++) d[i]=c[p[i]]+r;
        dfs(d,step-2);
    }
    int main()
    {
        int i;
        R(n); R(m); R(r); ans=-inf;
        for(i=1;i<=n;i++) R(a[i]);
        for(i=1;i<=n;i++) R(b[i]);
        for(i=1;i<=n;i++) R(k[i]);
        for(i=1;i<=n;i++) R(p[i]);
        dfs(a,m);
        Wl(ans);
        return 0;
    }
    View Code
     
  • 相关阅读:
    jmeter_逻辑控制器
    Mysql-10 存储过程
    Mysql-9 视图
    NAS性能测试
    win系统定时任务设置
    服务端监控有哪些客户端链接了服务
    centos8 添加端口号
    centos8下安装gitlab服务
    【Unity】Galgame视觉小说游戏 其脚本解释器的一种实现
    【个人向】ctf比赛出的一道逆向游戏题——GameTime题解
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/11329845.html
Copyright © 2011-2022 走看看