http://poj.org/problem?id=1745
#include#include<string.h> int a[10001],n,m; bool dp[10001][101]; int main(void) { int i,j,t1,t2; scanf("%d%d",&n,&m); for(i=1;i<=n;i++) { scanf("%d",&a[i]); while(a[i]<0) a[i]+=m; a[i]=a[i]%m; } dp[1][a[1]]=true; for(i=2;i<=n;i++) { for(j=0;j ) { t1=j-a[i]; while(t1<0) t1+=m; t2=j+a[i]; dp[i][j]=dp[i-1][t1]||dp[i-1][t2%m]; } } if(dp[n][0]) printf("Divisible\n"); else printf("Not divisible\n"); return 0; }