比赛 |
4043级NOIP2022欢乐赛3rd |
评测结果 |
AAAAAAAAAA |
题目名称 |
界外科学 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2022-11-04 21:11:31 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=40;
int n,m;
int a[N];
ll b[N],ans=0;
void dfs(int pt,int now,ll s){
if (pt==n+1) {
if (now<=m)ans=max(ans,s);
return ;
}
dfs(pt+1,now,s);
dfs(pt+1,now^a[pt],s+b[pt]);
return ;
}
ll f[N][1024+10]={0};
int main(){
freopen ("outsci.in","r",stdin);
freopen ("outsci.out","w",stdout);
scanf("%d%d",&n,&m);int mxv=0;
for (int i=1;i<=n;i++)scanf("%d",&a[i]),mxv=max(mxv,a[i]);
for (int i=1;i<=n;i++)scanf("%lld",&b[i]);
if (n<=20){
dfs(1,0,0);
printf("%lld\n",ans);
}
else if (m<=100&&mxv<=100){
int v=1;
while(v-1<=mxv)v*=2;
v--;
memset(f,-0x3f,sizeof(f));
f[0][0]=0;
for (int i=1;i<=n;i++){
for (int j=0;j<=v;j++){
f[i][j]=max(f[i-1][j],f[i-1][j^a[i]]+b[i]);
}
}
for (int i=0;i<=m;i++)ans=max(ans,f[n][i]);
printf("%lld\n",ans);
}
else{
for (int i=1;i<=n;i++){
if (b[i]>0)ans+=b[i];
}
printf("%lld\n",ans);
}
return 0;
}