| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
///#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
int a[10010];
int dp[10010][110];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1; i<=n; i++)
{
scanf("%d",a+i);
while(a[i]<0)
a[i]+=m;
a[i]%=m;
}
for(int i=1; i<=n; i++)
{
for(int j=0; j<m; j++)
{
int t=j-a[i];
while(t<0)
t+=m;
if(dp[i-1][j]==1)
dp[i][(j+a[i])%m]=dp[i][t%m]=1;
}
}
puts(dp[n][0]?"Divisible":"Not divisible");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator