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

直接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+5;
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 = 1; i <= n; i++){
        int x; scanf("%d",&x);
        if(!fg){
            x %= m;
            dp[x][i] = true;
            for(int k = 0; k <= m; k++){
                dp[k][i] = dp[k][i]||dp[k][i-1];
                if(dp[k][i-1]){
                    dp[(k+x)%m][i] = true;
                }
            }
            if(dp[0][i]) fg = true;
        }
    }
    if(fg) puts("YES");
    else puts("NO");
    return 0;
}
时间: 2024-10-11 18:23:12

Codeforces Round #319 (Div. 2) B Modulo Sum的相关文章

Codeforces Round #319 (Div. 2) C Vasya and Petya&#39;s Game

因为所有整数都能被唯一分解,p1^a1*p2^a2*...*pi^ai,而一次询问的数可以分解为p1^a1k*p2^a2k*...*pi^aik,这次询问会把所有a1>=a1k && a2 >= a2k &&... a3 >= a3k的数从原来的集合中分开.ai表示pi的幂. 那么只有当这个数的素因子的最大幂都被询问过一次,这个数才能确定.因此答案是所有的不大于n的只有一个素因子的数. #include<bits/stdc++.h> using

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

Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Description Input Output Sample Input 51 2 1 2 1 Sample Output 1 1 1 2 2 题解:这个题有做慢了,这种题做慢了和没做出来区别不大... 读题的时候脑子里还意识到素数除了2都是奇数,读完之后就脑子里就只剩欧拉筛了,贪心地构造使得前缀和是连续的素数,那

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

Div. 2 Multiplication Table (577A) 题意: 给定n行n列的方阵,第i行第j列的数就是i*j,问有多少个格子上的数恰为x. 1<=n<=10^5, 1<=x<=10^9 题解: 送分题…对于每一行,判断是否存在数x即可…也可以枚举x的因子判断是否出现在表内… #include<cstdio>#include<cstring>inlineint read(){int s =0;char c;while((c=getchar())

Codeforces Round #344 (Div. 2) E. Product Sum 二分斜率优化DP

E. Product Sum Blake is the boss of Kris, however, this doesn't spoil their friendship. They often gather at the bar to talk about intriguing problems about maximising some values. This time the problem is really special. You are given an array a of

Codeforces Round #575 (Div. 3) B. Odd Sum Segments (构造,数学)

B. Odd Sum Segments time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given an array a consisting of n integers a1,a2,-,an. You want to split it into exactly k non-empty non-intersecting

Codeforces Round #319 (Div. 2) D

E A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u andv the condition

Codeforces Round #319 (Div. 2) E - Points on Plane

题目大意:在一个平面里有n个点,点坐标的值在1-1e6之间,让你给出一个遍历所有点的顺序,要求每个点走一次,且 曼哈顿距离之和小于25*1e8. 思路:想了一会就有了思路,我们可以把1e6的x,y坐标都分成2000份,每份500,然后这样整个平面就被分成 了2000*2000个区域,然后按区域输出点就行了. 1 #include<bits/stdc++.h> 2 using namespace std; 3 int n; 4 vector<int> ans[2005][2005];

Codeforces Round #475 (Div. 2) C - Alternating Sum

等比数列求和一定要分类讨论!!!!!!!!!!!! 1 #include<bits/stdc++.h> 2 #define LL long long 3 #define fi first 4 #define se second 5 #define mk make_pair 6 #define pii pair<int,int> 7 #define ull unsigned long long 8 using namespace std; 9 10 const int N=1e6+7

codeforces 576c// Points on Plane// Codeforces Round #319(Div. 1)

题意:有n个点,找到一个顺序走遍这n个点,并且曼哈顿距离不超过25e8. 由于给的点坐标都在0-1e6之间.将x轴分成1000*1000,即1000长度为1块.将落在同一块的按y排序,编号为奇的块和偶的块一个升序,一个降序.有3个量值得关注.一是同一块中x的变化量,其实是不超过1000*n1,n1是第1块中点的数量.那么1000*n1+1000*n2......=1000*n<1e9.后两个量是同一块中y的高度差,另一个是本块最后一个和另一块第一个的高度差.这种做法下相邻两块这两个高度差的和是小