mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 1745_non_cease.cpp
From http://blog.csdn.net/non_cease/article/details/6895791
This commit is contained in:
parent
6b432870c6
commit
3f81dbcef7
46
POJ/1745_non_cease.cpp
Normal file
46
POJ/1745_non_cease.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cmath>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#define N 10002
|
||||||
|
#define K 102
|
||||||
|
|
||||||
|
int num[N], n, k;
|
||||||
|
bool dp[N][K];
|
||||||
|
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
scanf("%d%d", &n, &k);
|
||||||
|
for(i = 1; i <= n; i++)
|
||||||
|
scanf("%d", &num[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Solve()
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
memset(dp, false, sizeof(dp));
|
||||||
|
dp[0][0] = true;
|
||||||
|
for(i = 1; i <= n; i++){
|
||||||
|
for(j = 0; j < k; j++){
|
||||||
|
if(dp[i-1][j]){
|
||||||
|
dp[i][abs(j + num[i]) % k] = true;
|
||||||
|
dp[i][abs(j - num[i]) % k] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[n][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
if(Solve())
|
||||||
|
printf("Divisible\n");
|
||||||
|
else
|
||||||
|
printf("Not divisible\n");
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user