博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp
阅读量:7284 次
发布时间:2019-06-30

本文共 1871 字,大约阅读时间需要 6 分钟。

B. Modulo Sum

Time Limit: 1 Sec  

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/577/problem/B

Description

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.

Input

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.

Sample Input

3 5

1 2 3

Sample Output

YES

HINT

 

题意

给你一堆数,然后问你是否有一些数加起来%m==0

题解:

当成背包dp做,空间为m,每一个物品的代价为a[i]就好了

注意滚动数组的时候,不要转移的时候被自己的状态转移了,注意一下就好了

代码:

//qscqesze#pragma comment(linker, "/STACK:1024000000,1024000000")#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 1000006#define mod 1001#define eps 1e-9#define pi 3.1415926int Num;//const int inf=0x7fffffff;const ll inf=999999999;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//*************************************************************************************int a[maxn];bool dp[maxn][2];int main(){ int n=read(),m=read(); for(int i=1;i<=n;i++) a[i]=read(),a[i]%=m; int flag = 0; for(int i=1;i<=n;i++) { dp[a[i]][1-flag] = 1; for(int j=1;j

 

转载地址:http://uhzjm.baihongyu.com/

你可能感兴趣的文章
Linux下搭建Redis集群、JedisCluster带密码访问
查看>>
CentOS7下安装Zookeeper-3.4.10
查看>>
敏捷AI | NLP技术在宜信业务中的实践【构建用户画像篇】
查看>>
python版亲戚关系计算器
查看>>
送给程序员们的经典电子书大礼包
查看>>
SQL注入关联分析
查看>>
应用Promise封装Ajax实践
查看>>
渗透&&探测 ( ICMP 篇)
查看>>
容器监控实践—Prometheus的配置与服务发现
查看>>
dubbo源码解析(三十九)集群——merger
查看>>
PAT A1022
查看>>
捋一捋React的生命周期
查看>>
【跃迁之路】【731天】程序员高效学习方法论探索系列(实验阶段488-2019.2.21)...
查看>>
HTTP中Accept与Content-Type区别
查看>>
RunC容器逃逸漏洞席卷业界,网易云如何做到实力修复?
查看>>
PAT A1043
查看>>
SAP S/4HANA生产订单的BAdI增强点之Initialize方法
查看>>
css加载会造成阻塞吗
查看>>
天天都在使用CSS,那么CSS的原理是什么呢?
查看>>
可视化开发脚手架
查看>>