搜索
奇技淫巧题
我们无视排列中所有>25的元素。因为由1~25组成的异或和为0的方案有1048576个,已经远大于50000。在这么多种方案下,一个序列拼起来模p几乎可以看作是一个随机函数,异或和为0跟拼起来模p等于0之间几乎没有相关性。那也就是说我们在1~25之内找不到合法解的概率是
(4999950000)1048576≈7.8∗10−10
推广一下,假设只考虑所有≤
2l
的数,那么由
1∼2l
组成的异或和为
0
的方案大约会有
在如此大概率能找到解的情况下,可以通过本题。
#include<cstdio>
#include<cstdlib>
#define N 50005
#define M 26
using namespace std;
namespace runzhe2000
{
int a[M], n, p, tmp, sta[M], top, base[M], pos[M];
void dfs(int x, int xorsum, int addsum)
{
if(top && !xorsum && ! addsum)
{
printf("Yes\n%d\n",top);
for(int i = 1; i <= top; i++)printf("%d ",sta[i]);
exit(0);
}
if(x > n) return;
dfs(x+1,xorsum,addsum);
sta[++top] = pos[x];
dfs(x+1,xorsum^a[x],(addsum*base[a[x]]+a[x]) % p);
--top;
}
void main()
{
tmp = 0; scanf("%d%d",&n,&p);
for(int i = 1; i <= n; i++)
{
int x; scanf("%d",&x);
if(x < M) a[++tmp] = x, pos[tmp] = i;
}
for(int i = 1; i <= 9; i++) base[i] = 10;
for(int i = 10; i < M; i++) base[i] = 100;
n = tmp;
dfs(1,0,0);
puts("No");
}
}
int main()
{
runzhe2000::main();
}