Divisibility
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9476   Accepted: 3300

Description

Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expressions that evaluate to different values. Let us, for example, take the sequence: 17, 5, -21, 15. There are eight possible expressions: 17 + 5 + -21 + 15 = 16 
17 + 5 + -21 - 15 = -14 
17 + 5 - -21 + 15 = 58 
17 + 5 - -21 - 15 = 28 
17 - 5 + -21 + 15 = 6 
17 - 5 + -21 - 15 = -24 
17 - 5 - -21 + 15 = 48 
17 - 5 - -21 - 15 = 18 
We call the sequence of integers divisible by K if + or - operators can be placed between integers in the sequence in such way that resulting value is divisible by K. In the above example, the sequence is divisible by 7 (17+5+-21-15=-14) but is not divisible by 5.

You are to write a program that will determine divisibility of sequence of integers.

Input

The first line of the input file contains two integers, N and K (1 <= N <= 10000, 2 <= K <= 100) separated by a space. 
The second line contains a sequence of N integers separated by spaces. Each integer is not greater than 10000 by it's absolute value. 

Output

Write to the output file the word "Divisible" if given sequence of integers is divisible by K or "Not divisible" if it's not.

Sample Input

4 7
17 5 -21 15

Sample Output

Divisible
#include <stdio.h>
#include <iostream>
using namespace std; int dp[][] = {};
int num[] = {}; int main()
{
int k, n;
scanf("%d%d", &n, &k);
for (int i = ; i < n; i++)
{
scanf("%d", &num[i]);
if (num[i] < )
{
num[i] *= -;
}
num[i] = num[i] % k;
}
dp[][num[]] = ;
for (int i = ; i < n; i++)
{
for (int j = ; j <= k; j++)
{
if (dp[i - ][j])
{
dp[i][(j + num[i]) % k] = ;
dp[i][(k + j - num[i]) % k] = ;
}
}
}
if(dp[n-][])
{
printf("Divisible\n");
}
else
{
printf("Not divisible\n");
}
return ;
}

POJ 1745 Divisibility的更多相关文章

  1. POJ 1745 Divisibility (线性dp)

    Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10598   Accepted: 3787 Des ...

  2. POJ 1745 Divisibility DP

    POJ:http://poj.org/problem?id=1745 A完这题去买福鼎肉片,和舍友去买滴~舍友感慨"这一天可以卖好几百份,每份就算赚一块钱..那么一个月..一年...&quo ...

  3. POJ 1745 Divisibility【DP】

    题意:给出n,k,n个数,在这n个数之间任意放置+,-号,称得到的等式的值能够整除k则为可划分的,否则为不可划分的. 自己想的是枚举,将所有得到的等式的和算出来,再判断它是否能够整除k,可是有1000 ...

  4. POJ 1745 【0/1 背包】

    题目链接:http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  5. POJ 1745 线性和差取余判断

    POJ 1745 线性和差取余判断 题目大意:每个数都必须取到,相加或相减去,问所有的方案最后的得数中有没有一个方案可以整除k 这个题目的难点在于dp数组的安排上面 其实也就是手动模仿了一下 比如 一 ...

  6. POJ 1745:Divisibility 枚举某一状态的DP

    Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11001   Accepted: 3933 Des ...

  7. [POJ 1745] Divisbility

    [题目链接] http://poj.org/problem?id=1745 [算法] DP [代码] #include <algorithm> #include <bitset> ...

  8. 1745 Divisibility

    Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14084 Accepted: 4989 Descrip ...

  9. POJ 1745

    #include <iostream> #define MAXN 10005 using namespace std; int _m[MAXN]; ]; int main() { //fr ...

随机推荐

  1. React项目搭建(脚手架)

    首先我们需要安装node环境:download nodejs:https://i.cnblogs.com/EditPosts.aspx?opt=1 找到你需要的版本和系统安装包下载并安装. 这时候你可 ...

  2. Warning: skipping non-radio button in group

    Question:   最近在开发中,设计了一个对话框来进行一系列的设定,其中有一组Radio Buttons(单选按钮),但在Debug下,发现对话的弹出有点延迟,经过分析,确定是因为在对话框弹出之 ...

  3. ios 自定义加载动画效果

    在开发过程中,可能会遇到各种不同的场景需要等待加载成功后才能显示数据.以下是自定义的一个动画加载view效果.      在UIViewController的中加载等到效果,如下 - (void)vi ...

  4. ubuntu 14.04 安装npm

    1. 安装 sudo apt install nodejs-legacy sudo apt install npm  

  5. Python 元组、字典、集合操作总结

    元组 a=('a',) a=('a','b') 特点 有序 不可变,不可以修改元组的值,无法为元组增加或者删除元素 元组的创建 a=('a',) a=('a','b') tuple('abcd') 转 ...

  6. dfs染色法判定二分图

    #include<iostream> #include<cstring> using namespace std; ][],color[],n; int dfs(int x,i ...

  7. idea快速生成实体类Entity

    1)打开idea 2)添加mysql的数据连接 3)生成类

  8. Hibernate的二级缓存使用(spring使用)

    (一)Hibernate的二级缓存策略的一般过程如下: 1) 条件查询的时候,总是发出一条select * from table_name where …. (选择所有字段)这样的SQL语句查询数据库 ...

  9. MongoDB在java中的使用

    在一年前就开始在项目中使用Mongodb作为爬虫(crawler)待下载URL.下载成功URL等的存储库,最近对项目进行版本更新,根据Mongodb的最近升级情况,也对项目中的Mongodb进行了相关 ...

  10. ios之NSURLRequest&NSURLConnection

    网络编程中一般都是经过  请求--->连接--->响应   (request  -->  connection  -->  response)这个过程. 一般的步骤是这样的: ...