2018 ACM-ICPC World Finals - Beijing F.Go with the Flow
先枚举所有的列长度
对于每种列长度,然后里面用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的更多相关文章
- ACM - ICPC World Finals 2013 F Low Power
原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 有n个机器,每个机器有2个芯片,每个 ...
- ACM - ICPC World Finals 2013 C Surely You Congest
原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 试题来源 ACM/ICPC World Fin ...
- ACM - ICPC World Finals 2013 A Self-Assembly
原题下载 : http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 这道题其实是2013年我AC的第一道题,非常的开心,这 ...
- ACM - ICPC World Finals 2013 H Матрёшка
原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 俄罗斯套娃是一些从外到里大小递减的传 ...
- ACM - ICPC World Finals 2013 D Factors
原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 一个最基本的算数法则就是大于1的整数 ...
- 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 ...
- ACM - ICPC World Finals 2013 I Pirate Chest
原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 题目翻译: 问题描述 海盗Dick受够了在公海上厮杀.抢劫 ...
- ACM - ICPC World Finals 2013 B Hey, Better Bettor
原题下载:http://icpc.baylor.edu/download/worldfinals/problems/icpc2013.pdf 这题真心的麻烦……程序不长但是推导过程比较复杂,不太好想 ...
- 2016 ACM/ICPC亚洲区大连站 F - Detachment 【维护前缀积、前缀和、二分搜索优化】
F - Detachment In a highly developed alien society, the habitats are almost infinite dimensional spa ...
随机推荐
- curl http code 0
使用curl进行post请求后,接收status code ,结果返回的结果是0 ,但是请求返回的数据是正常的. 检查后发现是执行顺序问题: $response = [ 'statusCode' =& ...
- BootStrap启动类
来源 本文整理自 <Tomcat内核设计剖析>.<Tomcat结构解析> 加上自己的理解.源码来自 Tomcat8.5 版本 // org.apache.catalina.st ...
- JNI由浅入深_8_JNI缓存字段和方法ID
获取字段ID和方法ID时,需要用字段.方法的名字和描述符进行一个检索.检索过程相对比较费时,因此本节讨论用缓存技术来减少这个过程带来的消耗.缓存字段ID和方法ID的方法主要有两种.两种区别主要在于缓存 ...
- rsync + mysql + gzip + --single-transaction
1.rsync -avz 172.16.2.61:~/vs/program/elasticsearch-5.0.0 --exclude=elasticsearch-5.0.0/data/* ./ 从其 ...
- VMware虚拟机安装Centos7图文教程
CentOS 是一个工业标准的 Linux 发行版,是红帽企业版 Linux 的衍生版本.你安装完后马上就可以使用,但是为了更好地使用你的系统,你需要进行一些升级.安装新的软件包.配置特定服务和应用程 ...
- 【js】javaScript 执行机制
javascript 是一门单线程语言(按照语句一行一行的执行) let a = '1'; console.log(a); let b = '2'; console.log(b); 这样子正常执行是没 ...
- 【PTA 天梯赛】L1-046 整除光棍(除法模拟)
这里所谓的“光棍”,并不是指单身汪啦~ 说的是全部由1组成的数字,比如1.11.111.1111等.传说任何一个光棍都能被一个不以5结尾的奇数整除.比如,111111就可以被13整除. 现在,你的程序 ...
- iview-cli 项目、iView admin 代理与跨域问题解决方案
iview-cli 项目.iView admin 跨域.代理问题解决方案 在webpack.dev.config.js文件中: 添加: devServer: { historyApiFallback: ...
- windows系统,MongoDB开启用户验证登录的正确姿势
MongoDB默认安装并没有开启用户名密码登录,这样太不安全了,百度出来的开启验证登录的文章,对初次使用MongoDB的小白太不友好了,总结下经验,自己写一份指引. 1,我的安装路径是C:\Progr ...
- Redis API的理解与使用
目录 一.通用命令 二.数据结构与内部编码 三.单线程架构 一.通用命令 Redis有五种数据结构,它们是键值对中的值,对于键来说有一些通用的命令.Redis的全局通用命令有:keys,dbsize, ...