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
     
  • 相关阅读:
    BZOJ2219数论之神——BSGS+中国剩余定理+原根与指标+欧拉定理+exgcd
    Luogu 3690 Link Cut Tree
    CF1009F Dominant Indices
    CF600E Lomsat gelral
    bzoj 4303 数列
    CF1114F Please, another Queries on Array?
    CF1114B Yet Another Array Partitioning Task
    bzoj 1858 序列操作
    bzoj 4852 炸弹攻击
    bzoj 3564 信号增幅仪
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/11329845.html
Copyright © 2011-2022 走看看