Codeforces 577B Modulo Sum
http://codeforces.com/problemset/problem/577/B
题意:有n个数,求有无一个子序列满足和是m的倍数
思路:用模下的背包做,发现n是十的六次方级别,但是有个神奇的性质,就是抽屉原理,当n大于等于m的时候,总会有sum[i]和sum[j]满足sum[i]%m=sum[j]%m,于是当n>=m的时候就可以特判掉,DP的复杂度就是O(n^2)的
总结:一定要记住,在模m下的前缀和这样的东西,一定要记得有抽屉原理!
然后这题的XX细节真是坑死我了
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
int a[],f[],n,m,g[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
n=read();m=read();
if (n>m){
printf("YES");
return ;
}
for (int i=;i<=n;i++) a[i]=read();
for (int i=;i<=n;i++){
for (int j=;j<=m;j++) g[j]=f[j];
for (int j=m-;j>=;j--)
if (f[j])
g[(a[i]%m+j)%m]=;
g[a[i]%m]=;
for (int j=;j<=m;j++) f[j]=g[j];
}
if (f[]) printf("YES");
else printf("NO");
return ;
}
Codeforces 577B Modulo Sum的更多相关文章
- 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 个数中 ...
- CodeForce 577B Modulo Sum
You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choo ...
- 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 ...
- 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/ ...
- 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 ...
- Codeforces Round #319 (Div. 2)B. Modulo Sum DP
B. Modulo Sum ...
- cf319.B. Modulo Sum(dp && 鸽巢原理 && 同余模)
B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- perl post 请求相关参数
$ua->post( $url, \%form ) $ua->post( $url, \@form ) $ua->post( $url, \%form, $field_name =& ...
- 【转】关于Adapter的The content of the adapter has changed问题分析 关于Adapter的The content of the adapter has changed问题分析
原文网址:http://www.cnblogs.com/monodin/p/3874147.html 1.问题描述 1 07-28 17:22:02.162: E/AndroidRuntime(167 ...
- hdu4622-Reincarnation(后缀自动机)
Problem Description Now you are back,and have a task to do:Given you a string s consist of lower-cas ...
- 用Update Select批量更新某一字段的值[可以跨库]
SQL:UPDATE test1 SET name = (SELECT y.name FROM DB2.dbo.test2 y WHERE test1.id = y.id)
- Ext中图片上传预览的问题,困扰了好几天终于解决了,记录下
{ columnWidth:.50, xtype:'textfield', style:"padding-top:5px", name:'goodsMainPhoto', id:' ...
- C# 插入排序算法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 利用java反射机制 读取配置文件 实现动态类载入以及动态类型转换
作者:54dabang 在spring的学习过程之中,我们能够看出通过配置文件来动态管理bean对象的优点(松耦合 能够让零散部分组成一个总体,而这些总体并不在意之间彼此的细节,从而达到了真正的物理上 ...
- HDU 多校联合练习赛2 Warm up 2 二分图匹配
Warm up 2 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total ...
- IOS6和IOS7的屏幕适配问题
自从IOS7出来以后,以前写在IOS6上或者更低版本的程序,跑在IOS7的模拟器上就会出现一些问题.最大的问题就是,所有的UI空间都会统一向上移动20个点(如果空间的y值为0,就会被StatusBar ...
- WebApi2官网学习记录---Cookie
Cookie的几个参数: Domain.Path.Expires.Max-Age 如果Expires与Max-Age都存在,Max-Age优先级高,如果都没有设置cookie会在会话结束后删除cook ...