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; }