要点

  • 一开始dp然后码力太辣鸡并且算法带假于是调了很久一交还WA在28……
  • 吐槽完毕。后来想拿栈优化dp时发现其实完全不需要dp,贪心选取即可,当前的不兼容就干脆不要它了,结果不会变差。然后想要什么就预处理什么即可。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std; const int maxn = 1505;
int n, a[maxn], sum[maxn], ans, val, ID;
int d[maxn * maxn], cnt;
vector<int> v[maxn * maxn];
vector<int> vv[maxn];
unordered_map<int, int> mp, L[maxn]; int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), sum[i] = sum[i - 1] + a[i];
for (int i = 1; i <= n; i++) {
for (int j = i - 1; ~j; j--) {
int t = sum[i] - sum[j];
d[++cnt] = t;
if (!L[i][t]) L[i][t] = j + 1, vv[i].push_back(t);
}
} sort(d + 1, d + 1 + cnt);
cnt = unique(d + 1, d + 1 + cnt) - d - 1;
for (int i = 1; i <= cnt; i++) mp[d[i]] = i; for (int i = 1; i <= n; i++) {
for (int j = 0; j < vv[i].size(); j++) {
int t = vv[i][j], id = mp[t];
if (v[id].empty() || v[id].back() < L[i][t]) {
v[id].push_back(i);
}
if (ans < v[id].size()) {
ans = v[id].size();
val = t;
ID = id;
}
}
} printf("%d\n", ans);
for (int i : v[ID]) {
printf("%d %d\n", L[i][val], i);
}
return 0;
}

Codeforces 1141F2(贪心、预处理)的更多相关文章

  1. CodeForces - 893D 贪心

    http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...

  2. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  3. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  4. Liebig's Barrels CodeForces - 985C (贪心)

    链接 大意:给定$nk$块木板, 要制作$n$个$k$块板的桶, 要求任意两桶容积差不超过$l$, 每个桶的容积为最短木板长, 输出$n$个桶的最大容积和 假设最短板长$m$, 显然最后桶的体积都在$ ...

  5. CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  6. 暴力贪心+预处理自动机——cf990E

    枚举每种灯管,然后找到代价最小的那种灯管 贪心策略:灯管从0开始向右放置,如果末尾是不能放置灯管的结点,那么要往回找到最近一个可以放置灯管的结点,在那里放置灯管 所以先预处理每个不能放置灯管的结点对应 ...

  7. C - Ordering Pizza CodeForces - 867C 贪心 经典

    C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...

  8. Codeforces 570C 贪心

    题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...

  9. Codeforces 732e [贪心][stl乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...

随机推荐

  1. python to 可执行文件

    cx_Freeze for Windows, Linux, and Mac OS X (Python 2.7, 3.x) pyinstaller for Windows, Linux, and Mac ...

  2. 每天一个linux命令(5):mkdir命令

    版权声明更新:2017-05-09博主:LuckyAlan联系:liuwenvip163@163.com声明:吃水不忘挖井人,转载请注明出处! 1 文章介绍 本文介绍了Linux下命令mkdir. 2 ...

  3. BZOJ_5359_[Lydsy1805月赛]寻宝游戏_DP

    BZOJ5359_[Lydsy1805月赛]寻宝游戏_DP Description begin.lydsy.com/JudgeOnline/upload/201805.pdf 我们需要找到一条权值最大 ...

  4. 51nod_1236_序列求和 V3 _组合数学

    51nod_1236_序列求和 V3 _组合数学 Fib(n)表示斐波那契数列的第n项,Fib(n) = Fib(n-1) + Fib(n-2).Fib(0) = 0, Fib(1) = 1. (1, ...

  5. hdu 2222 Keywords Search——AC自动机

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2222 第一道AC自动机! T了无数边后终于知道原来它是把若干询问串建一个自动机,把模式串放在上面跑:而且只 ...

  6. 跑monkey前开启/关闭下拉栏

    @echo off cls title 别忘了跑monkey啊 :menu cls color 0A echo. echo 1.禁用systemui并重启 echo. echo 2.启用systemu ...

  7. JVM StackOverflowError vs. OutOfMemoryError

    if the computation in a thread needs a larger Java Virtual Machine stack than is permitted, the Java ...

  8. xgene:WGS,突变与癌,RNA-seq,WES

     人类全基因组测序06 SNP(single nucleotide polymorphism):有了10倍以上的覆盖深度以后,来确认SNP信息,就相当可靠了. 一个普通黄种人的基因组,与hg19这个参 ...

  9. HDU 1532 Drainage Ditches (网络流)

    A - Drainage Ditches Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  10. C 汉字处理

    好像有个wchar_t类型的,这里不深究了,只研究char型(1个字符大小)的 1.定义 直接使用char,但每个汉字占据2个字符,所以必须以字符串形式存在 char s[10]; 2.定义时直接赋值 ...