Archie
记忆化搜索就好
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int m;
int x;
int a[10005];
int n,k;
int f[10005][105];
bool dfs(int no,int re){
if(f[no][re]!=-1){
return f[no][re];
}
if(no==n+1){
return re==0;
}
return f[no][re]=(dfs(no+1,(re+a[no])%k)|dfs(no+1,(re-a[no]+k)%k));
}
int main(){
scanf("%d",&m);
while(m--){
scanf("%d%d",&n,&k);
memset(f,-1,sizeof(f));
for(int i=1;i<=n;++i){
scanf("%d",&x);
a[i]=(x%k+k)%k;
}
if(dfs(1,0)){
printf("Divisible
");
}else{
printf("Not divisible
");
}
}
return 0;
}