Codeforces Round #319 (Div. 2) B Modulo Sum (dp,鸽巢)
直接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,鸽巢)的更多相关文章
- Codeforces Round #319 (Div. 2)B. Modulo Sum DP
B. Modulo Sum ...
- 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 ...
- cf319.B. Modulo Sum(dp && 鸽巢原理 && 同余模)
B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- Codeforces Round 319 # div.1 & 2 解题报告
Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1< ...
- Codeforces Round #319 (Div. 2)
水 A - Multiplication Table 不要想复杂,第一题就是纯暴力 代码: #include <cstdio> #include <algorithm> #in ...
- 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 ...
- 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 ...
随机推荐
- python translate maketrans 字符串替换
string1='abcd-1234' print(string1.translate(string1.maketrans('abc','ABC'))) a='aeiou' b=' string2=' ...
- MySQL 5.7 INFORMATION_SCHEMA 详解
refman mysql 5.7 INFORMATION_SCHEMA提供了对数据库元数据的访问,MySQL服务器信息,如数据库或表的名称,列的数据类型,访问权限等. 有时也把这些信息叫做数据字典或系 ...
- 如何使用Node.js搭建一个服务器
在node环境中运行下面的代码 "use strict"; const http = require("http"), path = require(" ...
- python 之 函数 内置函数
5.15 内置函数 方法 含义 备注 abs(-1) 求绝对值 1 all ([1,'a',True]) 列表中所有元素的布尔值为真,最终结果才为真 True all ('') 传给all的可迭代对象 ...
- NetCore + Mysql + EF:No coercion operator is defined between types 'System.Int16' and 'System.Boolean',
总结三种解决办法: 1.Mysql升级到7 2.Nuget安装Pomelo.EntityFrameworkCore.MySql 2.2.0替代MySql.Data.EntityFrameworkCor ...
- iphone状态栏,导航栏,标签栏高度一览表
iphone状态栏,导航栏,标签栏高度一览表 设备分辨率 状态栏高度 导航栏高度 标签栏高度 iPhone6 plus 1242×2208 px 60px 132px 147px iPhon ...
- 【poj3764】The xor-longest Path
The xor-longest Path Description In an edge-weighted tree, the xor-length of a path p is defined as ...
- HDU-1498-50years,50colors(最大匹配, 枚举)
链接:https://vjudge.net/problem/HDU-1498#author=634579757 题意: 撞气球游戏,一个n*n的矩阵中,有不同颜色的气球,气球的颜色最多50种(从1到5 ...
- hdu1392凸包裸题
//极角排序 #include <bits/stdc++.h> #define sqr(x) ((x)*(x)) using namespace std; ],top; struct PO ...
- loj2734「JOISC 2016 Day 2」女装大佬 || 洛谷P3615 如厕计划
loj2734 洛谷P3615 http://218.5.5.242:9021/problem/185 不会做... 题解(来自ditoly): 这一步更详细的解释(来自kkksc03): 还是从后面 ...