POJ 1745
1 #include <iostream> 2 #define MAXN 10005 3 using namespace std; 4 5 int _m[MAXN]; 6 bool dp[MAXN][100]; 7 8 int main() 9 { 10 //freopen("acm.acm","r",stdin); 11 int n; 12 int k; 13 int i; 14 int j; 15 cin>>n; 16 cin>>k; 17 for(i = 0; i < n; ++ i) 18 { 19 cin>>_m[i]; 20 } 21 22 for(i = 0; i < n; ++ i) 23 { 24 _m[i] %= k; 25 while(_m[i] < 0) 26 { 27 _m[i] += k; 28 } 29 } 30 31 dp[0][_m[0]] = true; 32 33 for(i = 1; i < n; ++ i) 34 { 35 for(j = 0; j < k; ++ j) 36 { 37 if(dp[i-1][j]) 38 { 39 dp[i][(j+_m[i])%k] = true; 40 int tem; 41 tem = j-_m[i]; 42 tem %= k; 43 while(tem < 0) 44 { 45 tem += k; 46 } 47 dp[i][tem] = true; 48 } 49 } 50 } 51 52 if(dp[n-1][0]) 53 { 54 cout<<"Divisible"<<endl; 55 } 56 else 57 { 58 cout<<"Not divisible"<<endl; 59 } 60 61 }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com