POJ 1745 Divisibility
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 9476 | Accepted: 3300 |
Description
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 second line contains a sequence of N integers separated by spaces. Each integer is not greater than 10000 by it's absolute value.
Output
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的更多相关文章
- POJ 1745 Divisibility (线性dp)
Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10598 Accepted: 3787 Des ...
- POJ 1745 Divisibility DP
POJ:http://poj.org/problem?id=1745 A完这题去买福鼎肉片,和舍友去买滴~舍友感慨"这一天可以卖好几百份,每份就算赚一块钱..那么一个月..一年...&quo ...
- POJ 1745 Divisibility【DP】
题意:给出n,k,n个数,在这n个数之间任意放置+,-号,称得到的等式的值能够整除k则为可划分的,否则为不可划分的. 自己想的是枚举,将所有得到的等式的和算出来,再判断它是否能够整除k,可是有1000 ...
- POJ 1745 【0/1 背包】
题目链接:http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- POJ 1745 线性和差取余判断
POJ 1745 线性和差取余判断 题目大意:每个数都必须取到,相加或相减去,问所有的方案最后的得数中有没有一个方案可以整除k 这个题目的难点在于dp数组的安排上面 其实也就是手动模仿了一下 比如 一 ...
- POJ 1745:Divisibility 枚举某一状态的DP
Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11001 Accepted: 3933 Des ...
- [POJ 1745] Divisbility
[题目链接] http://poj.org/problem?id=1745 [算法] DP [代码] #include <algorithm> #include <bitset> ...
- 1745 Divisibility
Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14084 Accepted: 4989 Descrip ...
- POJ 1745
#include <iostream> #define MAXN 10005 using namespace std; int _m[MAXN]; ]; int main() { //fr ...
随机推荐
- [Luogu1343]地震逃生 最大流
题目链接:https://www.luogu.org/problem/show?pid=1343 dinic跑最大流. #include<cstdio> #include<cstri ...
- mount_cd9660:/dev/acd0: Input/output error
mount -t cd9660 /dev/acd0 /cdrom g_vfs_done():acd0[READ(offset32768, length=204]error =5 mount_cd966 ...
- (十一)mybatis之映射器(select)
映射器 映射器的主要元素有八种: 元素名称 描述 select 查询语句,可自定义参数 insert 插入语句,执行后返回插入的条数 update 更新语句,执行后返回更新的条数 delete 删除语 ...
- vs和github同步开发步骤
首先,这是在visual studio中使用.需要了解关于vs同步github必不可少.下载安装破解什么的先完成vs. 1. 然后安装一个vs中使用github的插件.vs自带的下载.这个是下载地址. ...
- Scrapy-架构
Scrapy架构(各组件的功能)及Scrapy引擎控制数据流的过程 1. Scrapy架构图(绿线是数据流向): □ Scrapy引擎(Engine):引擎负责控制数据流在系统的所有组件中流动,并在相 ...
- 有C++特色的极乐净土
闲的没事瞎打的 在win7下会走调,需要将win7的beep系统文件改成xp的,且主机装有蜂鸣器才能正常收听. beep文件的度盘地址(不过应该没人为了听个这个去改系统文件)(P.S.如果想要尝试,尽 ...
- shell脚本,通过一个shell程序计算n的阶乘。
[root@localhost ~]# cat jiechen.sh #!/bin/bash #设计一个shell程序计算n的阶乘,要求: #.从命令行接收参数n; #.在程序开始后立即判断n的合法性 ...
- -bash: xx: command not found 在有yum源情况下处理
-bash: xx: command not found 在有yum源情况下处理 yum provides "*/xx" ###"xx"代表某命令 或者 yu ...
- ios之ARC
本文部分实例取自iOS 5 Toturail一书中关于ARC的教程和公开内容,仅用于技术交流和讨论.请不要将本文的部分或全部内容用于商用,谢谢合作. 欢迎转载本文,但是转载请注明本文出处:http:/ ...
- ccf_201712-2
题目 问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针方向,3号小朋友坐在2号小朋友的顺时针方向,……,1号小朋友坐在n号小朋友的顺时针方向. 游戏开始,从1 ...