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. 搭建高可用mongodb集群(一)——mongodb配置主从模式

    转载自:LANCEYAN.COM 在大数据的时代,传统的关系型数据库要能更高的服务必须要解决高并发读写.海量数据高效存储.高可扩展性和高可用性这些难题.不过就是因为这些问题Nosql诞生了. NOSQ ...

  2. Java编程基础-反射

    一.java反射 1.反射:动态获取类的信息,以及动态调用对象的方法的功能.可以理解为动态看透类的能力. 2.主要功能:在运行时判断任意一个对象所属的类:在运行时构造任意一个类的对象:在运行时判断任意 ...

  3. error c2243:"类型转换" 转换存在,但无法访问

    今天在程序的中有一段class Quackable : QuackObservable,结果一直出现error c2243:"类型转换" 转换存在,但无法访问. 后来发现只要改成c ...

  4. 学习用5W1H来管理自己的项目/工作

    学习用5W1H来管理自己的项目/工作   最近开始需要系统化的思维模型,这只是一个开始,一下用脑图的形式来简介5W1H的具体内容: 先写xmind思维树的文本导出,后面附上图片.^ _ ^ 5W1H ...

  5. 为 Azure 应用服务配置连续部署工作流

    本快速入门介绍了如何将应用服务 GitHub 集成以实现连续部署工作流.在本教程中完成的所有操作均符合1元试用条件. 本快速入门介绍了如何将应用服务 GitHub 集成以实现连续部署工作流.在本教程中 ...

  6. webpack前端构建工具学习总结(三)之webpack.config.js配置文件

    Webpack 在执行的时候,除了在命令行传入参数,还可以通过指定的配置文件来执行.默认情况下,会搜索当前目录的 webpack.config.js 文件,这个文件是一个 node.js 模块,返回一 ...

  7. 洛谷 P1363 幻想迷宫

    题目描述 背景 Background (喵星人LHX和WD同心协力击退了汪星人的入侵,不幸的是,汪星人撤退之前给它们制造了一片幻象迷宫.) WD:呜呜,肿么办啊…… LHX:momo...我们一定能走 ...

  8. COGS 36. 求和问题

    时间限制:1.2 s   内存限制:128 MB [问题描述]     在一个长度为n的整数数列中取出连续的若干个数,并求它们的和. [输入格式]     输入由若干行组成,第一行有一个整数n    ...

  9. elasticsearch更新操作问题

    elasticsearch在更新的时候,是通过id进行管理的,我们在前台传入id操作,id如果与elasticsearch相同,则覆盖,否则新增一条记录.且elasticsearch中的插入一条记录和 ...

  10. The Django Book 第三章 试图和URL配置

    之前自学Django也有一段时间了,再过一个月就要入职新公司了(Python Django开发),即使现在还在入门级徘徊,再好好把Django基础过一遍吧. The Django Book 第三章 试 ...