先枚举所有的列长度

对于每种列长度,然后里面用dp算

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f; char seq[85];
int Len[2505];
int mp[2][200005];
int has[200005];
int sufLen[2505]; int Get(int flag, int tmp, int cnt) {
if(has[tmp] == cnt) return mp[flag][tmp];
else return 0;
} int main() {
int n;
while(~scanf("%d", &n)) {
// memset(mp, 0, sizeof(mp));
int ansCnt = -1; int ansPos;
int maxLen = -1;
int sumLen = 0; for(int i = 0; i < n; ++i) {
scanf("%s", seq);
int len = strlen(seq);
maxLen = max(maxLen, len);
Len[i] = len;
sumLen += len + 1;
}
Len[n] = INF; for(int i = 0; i < n; ++i) {
sufLen[i] = (i ? sufLen[i-1] : 0) + Len[i] + 1;
} int cnt = 0;
// for(int t1 = 0; t1 < n; ++t1) {
// for(int t2 = t1; t2 < n; ++t2) {
for(int i = maxLen; i <= sumLen; ++i) {
// int i = sufLen[t2] - (t1 ? sufLen[t1 - 1] : 0) - 1;
if(i < maxLen || (sumLen / i < ansCnt) ) continue;
cnt ++;
// std::printf("%d\n", i);
int j = 0; int ans = -1;
int flag = 0;
// map<int, int> mp[2];
// for(int z = 0; z <= i + 1; ++z) {
// mp[0][z] = mp[1][z] = 0;
// }
while(j < n) {
int tmp = 0;
for(int z = 0; z <= i + 1; ++z) {
mp[flag ^ 1][z] = 0;
}
int pre = j;
// mp[flag ^ 1].clear();
while(tmp + Len[j] <= i && j < n) {
tmp += Len[j] + 1;
j ++;
if(tmp + Len[j] <= i) {
mp[flag ^ 1][tmp] = max(max(Get(flag, tmp-1, cnt), Get(flag, tmp, cnt)), Get(flag, tmp+1, cnt)) + 1;
has[tmp] = cnt + 1;
ans = max(ans, mp[flag ^ 1][tmp]);
}
}
cnt ++;
if(pre == j)
break;
flag ^= 1;
// for(auto it = mp[flag].begin(); it != mp[flag].end(); ++it) {
// printf("%d %d:", it->first, it->second);
// }
// printf("\n");
} // printf("%d\n", ans);
if(ans > ansCnt || (ans == ansCnt && i < ansPos)) {
ansCnt = ans;
ansPos = i;
}
}
// }
// } std::printf("%d %d\n", ansPos, ansCnt);
}
return 0;
}

2018 ACM-ICPC World Finals - Beijing F.Go with the Flow的更多相关文章

  1. ACM - ICPC World Finals 2013 F Low Power

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 有n个机器,每个机器有2个芯片,每个 ...

  2. ACM - ICPC World Finals 2013 C Surely You Congest

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 试题来源 ACM/ICPC World Fin ...

  3. ACM - ICPC World Finals 2013 A Self-Assembly

    原题下载 : http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 这道题其实是2013年我AC的第一道题,非常的开心,这 ...

  4. ACM - ICPC World Finals 2013 H Матрёшка

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 俄罗斯套娃是一些从外到里大小递减的传 ...

  5. ACM - ICPC World Finals 2013 D Factors

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 一个最基本的算数法则就是大于1的整数 ...

  6. hihocoder 1388 &&2016 ACM/ICPC Asia Regional Beijing Online Periodic Signal

    #1388 : Periodic Signal 时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal proce ...

  7. ACM - ICPC World Finals 2013 I Pirate Chest

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 海盗Dick受够了在公海上厮杀.抢劫 ...

  8. ACM - ICPC World Finals 2013 B Hey, Better Bettor

    原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 这题真心的麻烦……程序不长但是推导过程比较复杂,不太好想 ...

  9. 2016 ACM/ICPC亚洲区大连站 F - Detachment 【维护前缀积、前缀和、二分搜索优化】

    F - Detachment In a highly developed alien society, the habitats are almost infinite dimensional spa ...

随机推荐

  1. Linux 内核版本号查看

    简要:1,lsb_release -a 查看linux系统版本 2,uname -a 查看内核版本

  2. cocos2d-x开发: 如何从项目中分离出接口范例

    cocos2d-x开发,包括核心模块接口开发和脚本部分的业务逻辑实现.从上层应用需求开始说,脚本在做业务逻辑实现的时候, 很多时候都需要依赖底层的接口功能,但是不是所有的人都可以游刃有余的去明白该怎么 ...

  3. iOS利用block实现链式编程方法(Objective-C链式编程)

    objc利用block实现链式编程方法 因为不好读.block和其他语言的匿名函数一样,很多程序员刚开始很难主动去用他. 本文描述block作为属性的实际使用,看懂block,并讲解如何利用block ...

  4. c#网络传输

    接着前面简单讲的,给大家聊聊服务开发. 网络传输 先说网络传输开发,总体来说,可以看成4中模型 我们把传输过程看做网线,那么在通过传输的过程中.2边就涉及池化问题,也就是我们常见的异步传输. 在业务端 ...

  5. CentOS7进行OpenStack(queens)最小化部署实验出现的问题与解决过程

    注:此文为<OpenStack(queens)最小化搭建记录——控制与计算共两个节点>的补充 1.chrony时间同步服务搭建的时候,出现计算节点无法与控制节点同步.(controller ...

  6. Spring MVC中如何解决POST请求中文乱码问题,GET的又如何处理呢

    在web.xml中配置过滤器 GET请求乱码解决: 在Tomcat中service.xml中

  7. encodeURIComponent编码反斜杠 \ (正则匹配)

    记录一个小bug... 前言废话: 1. 功能需求:修改输入框的内容,获取字符串传给后端保存. 2. bug历程:刚开始直接获取value值传过去.后来测试发现%&这些特殊字符无法传递后,在前 ...

  8. 使用PHP生成二维码支持自定义logo

    require_once 'phpqrcode/phpqrcode.php'; //引入类库 $text = "https://www.baidu.com/";//要生成二维码的文 ...

  9. 数据立方体(Cube)

    如上图所示,这是由三个维度构成的一个OLAP立方体,立方体中包含了满足条件的cell(子立方块)值,这些cell里面包含了要分析的数据,称之为度量值.显而易见,一组三维坐标唯一确定了一个子立方. 多位 ...

  10. FLINK流计算拓扑任务代码分析<一>

    我打算以 flink 官方的 例子 <<Monitoring the Wikipedia Edit Stream>> 作为示例,进行 flink 流计算任务 的源码解析说明. ...