Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

///

Posted by keys at 2012-08-08 19:40:56 on Problem 1745
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator