解题思路:dp表示的为dp[i][j]前i个数是否能够组成余数为j,是则为1 

#include <iostream>
using namespace std;
#define MAXN 10001

int dp[MAXN][101];

int posmod(int n,int k){		//正数取余
	n = n % k;
	while(n < 0) n+=k;
	return n;
}

int main(){
	int n,k;
	int i ,j ,tmp;
	int a[MAXN];
	while(cin>>n>>k){
		memset(dp,0,sizeof(dp));
		for(i = 1;i <= n;i++) cin>>a[i];
		dp[1][posmod(a[1],k)] = 1;
		for(i = 2;i <= n;i++){
			for(j = 0;j < k;j++){
				if(dp[i - 1][j]){
					dp[i][posmod(j + a[i],k)] = 1;
					dp[i][posmod(j - a[i],k)] = 1;
				}
			}
		}
		if(dp[n][0]){
			cout<<"Divisible"<<endl;
		}else{
			cout<<"Not divisible"<<endl;
		}
	}
	return 0;
}