题目:http://codeforces.com/contest/888/problem/E 一看就是折半搜索?……然后排序双指针. 两个<m的数加起来如果>=m,一定不会更新答案.因为-m后的值比原来的两个数都小(a+b-m<a+m-m),不如它们去加0: 而如果两个数加起来<m,值比它们都大,可能更新答案. #include<iostream> #include<cstdio> #include<cstring> #include<al…
E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of…
[CF888E]Maximum Subsequence 题意:给你一个序列{ai},让你从中选出一个子序列,使得序列和%m最大. n<=35,m<=10^9 题解:不小心瞟了一眼tag就一下子知道怎么做了,吓得我赶紧把tag屏蔽了. 我们将原序列拆成两半,每一部分都暴力搜索出所有的子序列之和,用set存起来.然后枚举前一半的所有子序列和,设其为x,则使得总和%m最大的右半部分子序列和一定是所有<m-x的数中最大的那个,在set里找一下前驱就行了. #include <cstdio&…
一道比较套路的题,看到数据范围就差不多有想法了吧. 题目大意:给一个数列和\(m\),在数列任选若干个数,使得他们的和对\(m\)取模后最大 取膜最大,好像不能DP/贪心/玄学乱搞啊.\(n\le35\)?果断meet in middle 考虑我们已经搜出了序列前一半的解,那么怎么根据后面的结果合并出结果? 设我们现在得到的和为\(x\)(对\(m\)取膜后),我们令一个数\(y=m-x\),然后在前面的解中查找\(y\)的前驱即可 接下来进行简单的证明: 若可以找到前驱\(z\),由于\(z<…
888E - Maximum Subsequence 思路:折半枚举. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) ; int a[N]; set<int>s; int main() { ios::sync_with_stdio(false); cin.tie(); i…
原题传送门 E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequen…
Code: #include<cstdio> #include<algorithm> #include<cstring> #include<string> using namespace std; void setIO(string a){freopen((a+".in").c_str(),"r",stdin),freopen((a+".out").c_str(),"w",std…
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For examp…
[CF888E]Maximum Subsequence(meet in the middle) 题面 CF 洛谷 题解 把所有数分一下,然后\(meet\ in\ the\ middle\)做就好了. 一侧的数正序,另一侧倒序,这样子指针单调就做完了. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include&l…
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For examp…