先枚举所有的列长度

对于每种列长度,然后里面用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. UVALive - 6837 Kruskal+一点性质(暴力枚举)

    ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens requested constru ...

  2. datatable的excel导入,其中有关于datatables的很多参数设置

    datatable的excel导入,其中有关于datatables的很多参数设置 http://www.cnblogs.com/liyuhuan/p/5633095.html

  3. Ubuntu下配置jdk和tomcat

    一.配置jdk 更新系统 apt-get update 添加ppa add-apt-repository ppa:webupd8team/java 开始安装 apt-get install oracl ...

  4. C# 删除指定目录下的所有文件及文件夹

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  5. js 实现内容的展开和收缩

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. Redis的特性以及优势(附官网)

    NoSQL:一类新出现的数据库(not only sql) 泛指非关系型的数据库 不支持SQL语法 存储结构跟传统关系型数据库中的那种关系表完全不同,nosql中存储的数据都是KV形式 NoSQL的世 ...

  7. Python 正则:前后界定和前后非界定

    在用正则去匹配识别手机号.QQ.微信号的时候,往往由于输入的文本可能非常的另类,比如,没有标点和隔断,这时`^`和`$`就用不上了. 不用其实也可以识别的,但是有个问题,手机后是11位数字,QQ是5~ ...

  8. laravel5.5源码笔记(一、入口应用的初始化)

    laravel的项目入口文件index.php如下 define('LARAVEL_START', microtime(true)); require __DIR__.'/../vendor/auto ...

  9. [修正] Firemonkey Android 文字斜粗体显示不全的问题

    问题:Firemonkey Android 平台显示斜粗体文字时,文字右方会有显示不全的问题. 修正代码: 请将 FMX.FontGlyphs.Android.pas 复制到自己的工程目录下,再修改如 ...

  10. 在全志V3/V3s和索智S3/S3L上调试32MB NorFlash

    选取MX25L25635F作为调试对象,其他型号的NorFlash开发调试原理基本一致.为了使V3/V3s/S3/S3L识别32MB NorFlash并正常工作,主要针对以下三个部分进行开发和调试.下 ...