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 ... 
随机推荐
- Java 数据库操作oracle增删改查,通用封装基于hashmap
			pt1:首先安装oracle连接驱动 下载地址:https://pan.baidu.com/s/1jW_ofgU4eJmAn7Y2J5B46A 密码:epkz 1.将ojdbc6.jar导入项目中 ... 
- Linux  内核版本号查看
			简要:1,lsb_release -a 查看linux系统版本 2,uname -a 查看内核版本 
- C#中调用方法
			using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ... 
- volatile关键字到底做了什么?
			话不多说,直接贴代码 class Singleton { private static volatile Singleton instance; private Singleton(){} //双重判 ... 
- iOS 推送功能打包后获取不到deviceToken
			公司项目用ionic3构建, 用了极光推送插件(cordova-plugin-jpush). 开发时一切将各种Bundle Id, 推送证书等都绑定完测试一切正常. 可是要给测试人员打Ad-Hoc包时 ... 
- mysql当前用户user()与current_user()
			Mysql在进行登陆时,会去匹配mysql库中的user表,并赋予相应的权限,但是怎么知道我们当时的登陆的用户名及相应的权限呢? 在Mysql中,有两个函数,一个是user(),一个是current_ ... 
- 记一次学习PHP中的错误
			今天学习PHP时,回想起一段代码 <?php> $i = true; $o = true; $p = false; if($i or $o and $p){ echo '输出为'.'tru ... 
- Flume(2)-拓扑结构与Agent内部原理
			一. 拓扑结构 1. 串行模式 这种模式是将多个flume给顺序连接起来了,从最初的source开始到最终sink传送的目的存储系统.此模式不建议桥接过多的flume数量, flume数量过多不仅会影 ... 
- ECShop全系列版本远程代码执行漏洞复现
			前言 问题发生在user.php的display函数,模版变量可控,导致注入,配合注入可达到远程代码执行 漏洞分析 0x01-SQL注入 先看user.php $back_act变量来源于HTTP_R ... 
- C++快速开发样本工程的建立--编写常用组件
			在添加的main.h里面添加如下功能: 主要使用标准C++和boost,界面部分采用QT 1.运行目录环境 2.使用的字体 3.使用的样式 4.使用的主题 
