要点

  • 一开始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. UVA 111 简单DP 但是有坑

    题目传送门:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18201 其实是一道不算难的DP,但是搞了好久,才发现原来是题目没 ...

  2. 文件操作:os模块与os.path模块

    一.os与os.path 原创:http://www.cnblogs.com/lovemo1314/archive/2010/11/08/1871781.html os模块用于处理文件及文件夹,包括文 ...

  3. ACM学习历程—HDU2068 RPG的错排(组合数学)

    Description 今年暑假杭电ACM集训队第一次组成女生队,其中有一队叫RPG,但做为集训队成员之一的野骆驼竟然不知道RPG三个人具体是谁谁.RPG给他机会让他猜猜,第一次猜:R是公主,P是草儿 ...

  4. MySQL 用户管理与权限管理

    MySQL 用户管理与权限管理 -- 操作环境mysql> show variables like 'version';  +---------------+--------+| Variabl ...

  5. MySQL 5.7新特性

    新增特性 Security improvements. MySQL.user表新增plugin列,且若某账户该字段值为空则账户不能使用.从低版本MySQL升级至MySQL5.7时要注意该问题,且建议D ...

  6. window系统的HOST详解

    很多用户都知道在Window系统中有个Hosts文件(没有后缀名),在Windows 98系统下该文件在Windows目录,在Windows 2000/XP系统中位于C\Winnt\System32 ...

  7. Vijos1221:神秘的配方

    背景 每天中午的下课铃一响,浙江镇海中学的同学们都会冲出学校来附近的小饭馆吃饭,刹那间天昏地暗,飞砂走石,家家餐馆内都是一片黑压压的人 .馄饨店.饺子馆,在学校附近开一家红一家.身为镇海中学信息中心首 ...

  8. git学习 7 git每次push都输入用户名 密码

    用如下命令改成SSH的方式 git remote rm origin git remote add origin git@github.com:username/repository.git git ...

  9. 异常:Error: Aesthetics must either be length one, or the same length as the dataProblems:AData

    今天遇到一个异常,代码如下: set.seed(12345) require(ggplot2) AData <- data.frame(Glabel=LETTERS[1:7], A=rnorm( ...

  10. MVC之Control中使用AOP

    原文转载自http://www.cnblogs.com/iamlilinfeng/archive/2013/03/02/2940162.html 本文目标 一.能够使用Control中的AOP实现非业 ...