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 ...
随机推荐
- HDU 1050(楼道搬桌子问题)(不是贪心解法,思路很新颖)
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 所有流媒体协议,编解码规范和媒体封装格式的datasheet的下载地址
https://github.com/jiayayao/DataSheet All datasheet about stream protocol, encode-decode spec and me ...
- 下载RPM常用网址
网址一:http://www.rpm-find.net/linux/rpm2html/search.php 网址二:http://rpmfind.net/linux/rpm2html/search ...
- iOS之禁止所有输入法的表情
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSSt ...
- docker_Dockerfile_docker hub简单使用搭建nginx
Docker for Windows是Docker for Microsoft Windows 的Community Edition(CE).要下载Docker for Windows,请前往Dock ...
- 04.flume+kafka环境搭建
1.flume下载 安装 测试 1.1 官网下载,通过xshell从winser2012传到cent0s的/opt/flume目录中,使用rz命令 1.2 解压安装 tar -zxvf apache- ...
- centos6.9下安装python3.7
说明 以下所有操作都基于centos6.9 python3.7依赖openssl1.0.2,首先更新系统自带的openssl 建议 升级系统到centos7(系统openssl已升级到1.0.2) 升 ...
- 使用树莓派拍摄延时动画,制作GIF图
本期教大家将编写一个小脚本用树莓派来捕获多个图像,然后可以将这些图像组合成动画GIF,使用延时摄影功能,可以在几秒钟内查看非常慢的事情. 我们需要用到ImageMagick,这是一个用于图像处理的命令 ...
- Angular 7 版本
Angular 7 版本 这是跨整个平台的主要版本,更新包括核心框架,Angular Material和CLI. 如何更新到v7 可以访问update.angular.io以获取有关更新应用程序的详细 ...
- Linux入门进阶第三天——软件安装管理(下)
一.yum在线安装 之前的rpm包各种依赖性太强!安装复杂,yum的好处就来了: // yum 在redhat是付费服务 1.yum源文件 先进入到yum目录: 我们打开默认生效的Base包 2.光盘 ...