1299: [LLH邀请赛]巧克力棒(SG函数乱搞)

19 篇文章 0 订阅

题目
我是个十分擅长于背公式的选手。
直接 f [ s t a ] f[sta] f[sta]表示 s t a sta sta集合的未被拿出。
f [ s t a ] = m e x ( ⋃ r s t a ⊂ s t a f [ r s t a ]   x o r   s u m x o r [ s t a − r s t a ] ) f[sta] = mex(\bigcup_{rsta \subset sta} f[rsta]\ xor\ sumxor[sta-rsta]) f[sta]=mex(rstastaf[rsta] xor sumxor[starsta])
s u m x o r [ s t a ] = X O R i ∈ s t a a [ i ] sumxor[sta] = XOR_{i \in sta} a[i] sumxor[sta]=XORistaa[i]
直接SG硬上。
AC Code(3780 ms):

#include<bits/stdc++.h>
#define maxn 14
#define maxm 200005
using namespace std;

int n,a[maxn],f[1<<14],sum[1<<14],lg[1<<14];
int vis[maxm],tim;

int ser(int nsta){
	if(f[nsta]!=-1) return f[nsta];
	for(int tmp=nsta;tmp;tmp=((tmp-1)&nsta))
		ser(nsta-tmp);
	tim++;
	for(int tmp=nsta;tmp;tmp=((tmp-1)&nsta)){
		int res = ser(nsta-tmp);
		for(int i=0;i<n;i++) if(tmp>>i&1) res^=a[i];
		vis[min(res,maxm-1)]=tim;
	}
	for(f[nsta]=0;vis[f[nsta]]==tim;f[nsta]++);
	return f[nsta];
}
char ANS[2][5]={"NO","YES"};
int main(){
	for(int i=2;i<(1<<14);i++) lg[i]=lg[i>>1]+1;
	for(int T=10;T--;){
		scanf("%d",&n);
		for(int i=0;i<n;i++)	scanf("%d",&a[i]);
		memset(f,-1,sizeof f);
		f[0] = 0;
		printf("%s\n",ANS[ser((1<<n)-1)==0]);
	}
}

一看status,0ms的大佬???
大佬博客28ms
大佬博客高斯消元0ms
巧妙的构造。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值