题目大意:

输入n,m; ( 1 ≤ N ≤ 10000, 2 ≤ M ≤ 100 )

接下来n个数;Each integer is not greater than 10000 by it's absolute value.

判断他们按顺序做加减法后能否整除m

若能输出“Divisible”,否则输出“Not divisible”;

Sample Input

Sample #1
4 7
17 5 -21 15

Sample #2
4 5
17 5 -21 15

Sample Output

Sample #1
Divisible

Sample #2
Not divisible

对于第一个样例解释:

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

-14可整除7

#include <bits/stdc++.h>
using namespace std;
bool dp[][];
/// dp[i][j]表示第i个数时余数为j的状态存不存在 1为存在 0则不存在
int main()
{
int n,m,a;
while(~scanf("%d%d%d",&n,&m,&a))
{
memset(dp,,sizeof(dp));
dp[][(a%m+m)%m]=; // 到第1个数时 a%m 存在
for(int i=;i<=n;i++)
{
scanf("%d",&a);
a=fabs(a); a%=m; /// 防止出现负数 先取绝对值 对求余没影响
for(int j=;j<m;j++)
if(dp[i-][j]) // 若上一个数时 余j 的状态存在
dp[i][(j+a)%m]=dp[i][(j-a+m)%m]=;
/// 则可由 上个数余j的状态 推出
/// 到当前数时(+a或-a) 余(j+a)%m 和 余(j-a+m)%m
/// 两个状态可存在
}
if(dp[n][]) printf("Divisible\n");
else printf("Not divisible\n");
} return ;
}

NEERC 1999 Divisibility /// 同余DP oj22640的更多相关文章

  1. 同余dp

    先验知识: 余数的计算公式:c = a -⌊ a/b⌋ * b 其中,⌊ ⌋为向下取整运算符,向下取整运算称为Floor,用数学符号⌊ ⌋表示 题目: Consider an arbitrary se ...

  2. 2016 ACM-ICPC NEERC F. Foreign Postcards (概率DP)

    2016 ACM-ICPC NEERC F. Foreign Postcards 题意:有一串由C.W组成的字符串,每次截取长度为k(1<=k<=n且k随机)的前缀,如果该前缀首位为W,则 ...

  3. NEERC 1999 Advertisement /// oj22646

    题目大意: 输入k,n :k为每位慢跑者最少应看到的广告牌数 接下来n行 描述第 i 位慢跑者的途径路段 输出需要设立的广告牌数 接下来每行为设立地点 Sample Input 5 101 1020 ...

  4. 1745 Divisibility

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

  5. Poj/OpenJudge 1042 Gone Fishing

    1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...

  6. 《Python核心编程》第五章:数字

    PS:[笔记+代码+图片]在GitHub上持续更新,欢迎star:https://github.com/gdouchufu/Core-Python-Programming 本章大纲 介绍Python支 ...

  7. POJ 1745 Divisibility (线性dp)

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

  8. ZOJ 2042 Divisibility (DP)

    Divisibility Time Limit: 2 Seconds      Memory Limit:65536 KB Consider an arbitrary sequence of inte ...

  9. 算法训练 K好数 数位DP+同余定理

    思路:d(i,j)表示以i开头,长度为j的K好数的个数,转移方程就是 for(int u = 0; u < k; ++u) { int x = abs(i - u); if(x == 1) co ...

随机推荐

  1. NX二次开发-创建一个3 x 3矩阵UF_CSYS_create_matrix

    1 NX9+VS2012 #include <uf.h> #include <uf_csys.h> #include <uf_mtx.h> UF_initializ ...

  2. NX二次开发-UFUN关闭STL文件函数UF_STD_close_stl_file

    NX9+VS2012 #include <uf.h> #include <uf_obj.h> #include <uf_modl.h> #include <u ...

  3. NX二次开发-NXOPEN设置工程图表格注释字体workPart->Fonts()->AddFont("chinesef_fs", NXOpen::FontCollection::TypeNx);

    NX9+VS2012 #include <uf.h> #include <uf_tabnot.h> #include <NXOpen/Part.hxx> #incl ...

  4. Java-Class-C:org.springframework.http.ResponseEntity

    ylbtech-Java-Class-C:org.springframework.http.ResponseEntity 1.返回顶部 1. org.springframework.http Clas ...

  5. HDU-1226-超级密码-队列+广搜+大数取模

    Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息: 密码是一个C进制的数,并且只能由给定的M个数字构成,同 ...

  6. PAT_A1020#Tree Traversals

    Source: PAT A1020 Tree Traversals (25 分) Description: Suppose that all the keys in a binary tree are ...

  7. USACO 2008 January Silver Telephone Lines /// 二分最短路 邻接表dijkstra oj22924

    题目大意: 一共有N (1 ≤ N ≤ 1,000)个电线杆,有P P (1 ≤ P ≤ 10,000)对电线杆是可以连接的, 用几条线连接在一起的电线杆之间都可相互通信,现在想要使得电线杆1和电线杆 ...

  8. 学无止境的CSS(xHTML+CSS技巧教程资源大全)

    本文里面收集一些有关CSS的技巧.教程.工具和观点等,其中一些你也许早就运用的炉火纯青,也可能有的你听都没听说过.不管是新手还是高手,大家都继续学习吧. 一,Web 标准 要玩游戏,就得先了解规则.要 ...

  9. sql(7)

    EXCEPT是指在第一个集合中存在,但是不存在于第二个集合中的数据. EXCEPT 子句/运算符用于将两个 SELECT 语句结合在一起,并返回第一个 SELECT 语句的结果中那些不存在于第二个 S ...

  10. canvas基础用法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...