$CF241D Numbers$

problem

题目大意:

给你n个数和p,都小于50000要求留下若干个数字,使得剩下的数字异或为0,并且从左到右串联起来可以被p整除,求一种这样的方案。

搜索

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read () { LL res = 0 ;int f (1) ;char ch = getchar ();
    while (!isdigit(ch)) { if (ch == '-') f = -1 ;ch = getchar();}
    while (isdigit(ch)) res = (res << 1) + (res << 3) + (ch ^ 48) ,ch = getchar(); return res * f ;
}
template<class T>void write(T x){
  if(x>9) write(x/10);
  putchar(48+x%10);
}
int const maxn=1<<5;
int n,p,a[maxn],b[maxn],m,check,pos[maxn];
int inline pw(int x){
  return x<10? 10:100;
}
inline void dfs(int k,int x,int y,int num){
  if(x==0 and y==0 and num){
    puts("Yes"); write(num);putchar('
');
    for(register int i=1;i<=num;i++) write(b[i]),putchar(' '); exit(0);
  }
  if(k>m) return ;
  dfs(k+1,x,y,num);
  b[num+1]=pos[a[k]];
  dfs(k+1,x^a[k],(y*pw(a[k])+a[k])%p,num+1);
}
signed main () {
    n=read(),p=read();
    for(register int i=1;i<=n;i++) {
        int x=read();
        if(x<maxn) a[++m]=x,pos[x]=i;
    }
    dfs(1,0,0,0); puts("No");
    return 0;
}
不存在十全十美的文章 如同不存在彻头彻尾的绝望
原文地址:https://www.cnblogs.com/qf-breeze/p/10460727.html