直接O(n*m)的dp也可以直接跑过。

因为上最多跑到m就终止了,因为前缀sum[i]取余数,i = 0,1,2,3...,m,有m+1个余数,m的余数只有m种必然有两个相同。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+;
int cnt[maxn];
bool dp[maxn][maxn];
#define Y { puts("YES"); return 0; }
int main()
{
//freopen("in.txt","r",stdin);
int n,m; scanf("%d%d",&n,&m);
bool fg = false;//n>m;
for(int i = ; i <= n; i++){
int x; scanf("%d",&x);
if(!fg){
x %= m;
dp[x][i] = true;
for(int k = ; k <= m; k++){
dp[k][i] = dp[k][i]||dp[k][i-];
if(dp[k][i-]){
dp[(k+x)%m][i] = true;
}
}
if(dp[][i]) fg = true;
}
}
if(fg) puts("YES");
else puts("NO");
return ;
}

Codeforces Round #319 (Div. 2) B Modulo Sum (dp,鸽巢)的更多相关文章

  1. Codeforces Round #319 (Div. 2)B. Modulo Sum DP

                                                             B. Modulo Sum                               ...

  2. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  3. Codeforces Round #319 (Div. 2) B. Modulo Sum 抽屉原理+01背包

    B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  4. cf319.B. Modulo Sum(dp && 鸽巢原理 && 同余模)

    B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...

  6. Codeforces Round 319 # div.1 & 2 解题报告

    Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...

  7. Codeforces Round #319 (Div. 2)

    水 A - Multiplication Table 不要想复杂,第一题就是纯暴力 代码: #include <cstdio> #include <algorithm> #in ...

  8. Codeforces Round #302 (Div. 2).C. Writing Code (dp)

    C. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard inp ...

  9. Codeforces Round #338 (Div. 2) C. Running Track dp

    C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...

随机推荐

  1. HDU - 5887 2016青岛网络赛 Herbs Gathering(形似01背包的搜索)

    Herbs Gathering 10.76% 1000ms 32768K   Collecting one's own plants for use as herbal medicines is pe ...

  2. 一次偶然的点开一盏灯引发的SEO初识

    事情是这样,不小心点开了dev tools的审计(audits)面板,点开了灯之后,画风如下 emmm, SEO 跑了满分也,好奇宝宝就往下滚到SEO区域,发现了如下新大陆 嗯,原来是应用满足了打钩的 ...

  3. MYSQL中coalesce函数的用法

    coalesce():返回参数中的第一个非空表达式(从左向右依次类推): 例如: select coalesce(null,4,5); // 返回4 select coalesce(null,null ...

  4. Git 分支管理 不使用Fast forward模式进行合并 分支管理策略

    通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的comm ...

  5. python创建矩阵

    创建二维数组的办法 直接创建(不推荐) 列表生产式法(可以去列表生成式 - 廖雪峰的官方网站学习) 使用模块numpy创建 举个栗子: 创建一个3*3矩阵,并计算主对角线元素之和. import nu ...

  6. Netty源码分析(七):初识ChannelPipeline

    ChannelPipeline单看名称就可以知道Channel的管道.本篇将结合它的默认实现类DefaultChannelPipeline来对它做一个简单的介绍. 示例图 上图是官方提供的Channe ...

  7. 聊聊 Laravel 5.5 的 「自动发现」

    ThinkSNS是什么? ThinkSNS(简称TS),一款全平台综合性社交系统,目前最新版本为ThinkSNS+.ThinkSNS V4 ThinkSNS[简]. 看了Taylor Otwell发表 ...

  8. HBase中报错 java.lang.NoClassDefFoundError: com/google/protobuf/LiteralByteString

    Protobuf(全称 Protocol Buffers)是 Google 开发的一种数据描述语言,能够将结构化数据序列化,可用于数据存储.通信协议等方面.在 HBase 里面用使用了 Protobu ...

  9. python进阶10 MySQL补充 编码、别名、视图、数据库修改

    python进阶10 MySQL补充    编码.别名.视图.数据库修改 一.编码问题 #MySQL级别编码 #修改位置: /etc/mysql/mysql.conf.d/mysqld.cnf def ...

  10. python isinstance函数 判断元素是否是字符串、int型、float型

    isinstance(1, int) 判断是否是int型isinstance(1.0, float) 判断是否是float型isinstance(s, str) 判断是否是字符串型isinstance ...