CodeForce 577B Modulo Sum
You are given a sequence of numbers a1, a2, ..., an, and a number m.
Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.
The first line contains two numbers, n and m (1 ≤ n ≤ 106, 2 ≤ m ≤ 103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Examples
3 5
1 2 3
YES
1 6
5
NO
4 6
3 1 1 3
YES
6 6
5 5 5 5 5 5
YES
Note
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequen
OJ-ID:
CodeForce 577B
author:
Caution_X
date of submission:
20191019
tags:
dp
description modelling:
给一个序列,找一个子序列使之mod m =0
major steps to solve it:
dp[i]:表示取模后得到了i
1.遍历序列,对每一个元素更新dp,判断能否得到dp[0]
AC code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[],dp[],tmp[];
int main()
{
ll n,m;
scanf("%lld%lld",&n,&m);
for(int i=;i<n;i++) {
scanf("%lld",&a[i]);
}
for(int i=;i<n;i++) {
if(dp[]) break;
for(int j=;j<=m-;j++) {
if(dp[j]) {
tmp[(j+a[i])%m]=;
}
}
tmp[a[i]%m]=;
for(int j=;j<=m-;j++) {
dp[j]=tmp[j];
}
}
if(dp[]) printf("YES\n");
else printf("NO\n");
return ;
}
CodeForce 577B Modulo Sum的更多相关文章
- Codeforces 577B Modulo Sum
http://codeforces.com/problemset/problem/577/B 题意:有n个数,求有无一个子序列满足和是m的倍数 思路:用模下的背包做,发现n是十的六次方级别,但是有个神 ...
- Codeforces 577B Modulo Sum:数学 结论【选数之和为m的倍数】
题目链接:http://codeforces.com/problemset/problem/448/C 题意: 给你n个数字,给定m. 问你是否能从中选出若干个数字,使得这些数字之和为m的倍数. 题解 ...
- codeforces 577B. Modulo Sum 解题报告
题目链接:http://codeforces.com/problemset/problem/577/B 题目意思:就是给出 n 个数(a1, a2, ..., an) 和 m,问能不能从这 n 个数中 ...
- CF 577B Modulo Sum
题意:给一个长度为n的正整数序列,问能不能找到一个不连续的子序列的和可以被m整除. 解法:抽屉原理+dp.首先当m<n时一定是有答案的,因为根据抽屉原理,当得到这个序列的n个前缀和%m时,一定会 ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- cf319.B. Modulo Sum(dp && 鸽巢原理 && 同余模)
B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 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/ ...
- Modulo Sum(背包 + STL)
Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 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 ...
随机推荐
- 项目中出现多个域名下的Cookie
前言:我们在查看一个项目的Cookie时,有时会看到多个域名下的Cookie,如下图: 其中一种常见的原因是:因为我们在项目中引用了另一个项目的资源.如下图: 重点:浏览器的一种默认机制:如果我们引用 ...
- DevExpress的分页Tab控件XtraTabControl控件的使用
场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...
- 初始HTML_表格
Html表格 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <ti ...
- 如何给HTML页面的文本设置字符和单词间距
设置字符和单词间距介绍 属性名 单位 描述 letter-spacing px 设置字符间距 word-spacing px 设置单词间距 letter-spacing设置字符间距 letter-sp ...
- 程序员编程时常用的mac快捷方式
fn + F2/F3 = 调节音量 commend + shift +k = 显示或隐藏键盘 commend+shift +h = iPhone返回主页面 commend+ shift + hh = ...
- [转]关于maven pom.xml中dependency type 为pom的应用
原文地址:http://blog.csdn.net/yao123long/article/details/49925659 dependency为什么会有type为pom,默认的值是什么?depend ...
- ElasticSearch安装及运行的坑
一.确认centos系统是为64位的,x86的不可以安装 1. 下载elasticsearch包 2. 用 tar -zxvf 解压包 3. 增加一个elk用户,elasticsearch7不可用ro ...
- MongoDB 副本集丢失数据的测试
在MongoDB副本集的测试中发现了一个丢数据的案例. 1. 概要描述 测试场景为:一主一从一验证 测试案例 step1 :关闭从副本: step 2 :向主副本中插入那条数据: step 3 :关闭 ...
- MySQL日常使用遵循的规范建议
一 . 基础规范 1.必须使用InnoDB存储引擎 解读:支持事务:支持行级锁:支持MVCC多版本控制:支持外键:死锁自动检测:并发性能更好.CPU及内存缓存页优化使得资源利用率更高. 2. 表字符 ...
- Jmeter Question 之 ‘批量执行SQL语句’
第一步: MySql数据库:jdbc:mysql://ip:3306/数据库名?useUnicode=true&characterEncoding=utf8&allowMultiQue ...