2580: [Usaco2012 Jan]Video Game

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 142  Solved: 96
[Submit][Status][Discuss]

Description

Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the only valid buttons. Bessie may press the buttons in any order she likes; however, there are only N distinct combos possible (1 <= N <= 20). Combo i is represented as a string S_i which has a length between 1 and 15 and contains only the letters 'A', 'B', and 'C'. Whenever Bessie presses a combination of letters that matches with a combo, she gets one point for the combo. Combos may overlap with each other or even finish at the same time! For example if N = 3 and the three possible combos are "ABA", "CB", and "ABACB", and Bessie presses "ABACB", she will end with 3 points. Bessie may score points for a single combo more than once. Bessie of course wants to earn points as quickly as possible. If she presses exactly K buttons (1 <= K <= 1,000), what is the maximum number of points she can earn? 
 
给出n个ABC串combo[1..n]和k,现要求生成一个长k的字符串S,问S与word[1..n]的最大匹配数

Input

Line 1: Two space-separated integers: N and K. * Lines 2..N+1: Line i+1 contains only the string S_i, representing combo i.

Output

Line 1: A single integer, the maximum number of points Bessie can obtain.

Sample Input

3 7 ABA CB ABACB

Sample Output

4

HINT

The optimal sequence of buttons in this case is ABACBCB, which gives 4 points--1 from ABA, 1 from ABACB, and 2 from CB.

Source

 

[Submit][Status][Discuss]

总串长只有300,即Trie树大小<=300,那建个AC自动机,拎出Fail树,在上面给每个EndPos的子树+1,此时每个结点的权值就是到达这个结点会新增的匹配数。在一张有向有环图上走1000步,使得经过点的权值和最大,而且点数<=300,那就DP好了,f[i][j]表示当前在i点,已经走了j步,得到的最大权值,向i的每个出边做转移就好。

@Author: YouSiki

BZOJ 2580: [Usaco2012 Jan]Video Game的更多相关文章

  1. BZOJ_2580_[Usaco2012 Jan]Video Game_AC自动机+DP

    BZOJ_2580_[Usaco2012 Jan]Video Game_AC自动机+DP Description Bessie is playing a video game! In the game ...

  2. BZOJ2580: [Usaco2012 Jan]Video Game(AC自动机)

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 159  Solved: 110[Submit][Status][Discuss] Descriptio ...

  3. [Usaco2012 Jan]Video Game

    Description Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the ...

  4. [bzoj 3048] [Usaco2013 Jan]Cow Lineup

    [bzoj 3048] [Usaco2013 Jan]Cow Lineup Description 给你一个长度为n(1<=n<=100,000)的自然数数列,其中每一个数都小于等于10亿 ...

  5. bzoj 1576: [Usaco2009 Jan]安全路经Travel 树链剖分

    1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 665  Solved: 227[Sub ...

  6. [BZOJ 3888] [Usaco2015 Jan] Stampede 【线段树】

    题目链接:BZOJ - 3888 题目分析 首先,计算出每个线段在 x 坐标 0 处出现的时间开始点和结束点,就转成了时间轴上的线段. 然后就是看每条线段是否被 y 比它小的线段完全覆盖了.注意求出的 ...

  7. Bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 传递闭包,bitset

    1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 891  Solved: 590 ...

  8. [BZOJ 1576] [Usaco2009 Jan] 安全路经Travel 【树链剖分】

    题目链接: BZOJ - 1576 题目分析 首先Orz Hzwer的题解. 先使用 dijikstra 求出最短路径树. 那么对于一条不在最短路径树上的边 (u -> v, w) 我们可以先沿 ...

  9. 动态规划(状态压缩):BZOJ 2621 [Usaco2012 Mar]Cows in a Skyscraper

      2621: [Usaco2012 Mar]Cows in a Skyscraper Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 303  Sol ...

随机推荐

  1. anaconda+pycharm的安装和应用

    至于anaconda的安装与pycharm的安装在此不做多说,主要说下遇到的问题. 问题描述: 安装anaconda后,pip下载的第三方库调用不到. 原因分析: anaconda自带的python3 ...

  2. Flink架构分析之HA

    抽象 LeaderElectionService 这个接口用于从一组竞选者中选出一个leader,其start方法需要传递一个LeaderContender竞选者作为参数,如果有多个竞选者,则每一个竞 ...

  3. Maven ResourceBundle.getBundle读取Properties异常MissingResourceException: Can't find bundlei解决方法

    参考:https://blog.csdn.net/thousa_ho/article/details/72817616 问题描述 ResourceBundle读取properties配置文件提示 Mi ...

  4. RHEL6.4 xclock安装小记

    http://blog.sina.com.cn/s/blog_623630d50101tc67.html

  5. PowerDesgner的视图显示设置教程

    一.简介 PowerDesgner是一款实用的数据库原型设计软件,但一些新手往往会觉得不好上手,应小伙伴需要,整理了一下PowerDesgner的视图显示设置教程: 首先,PowerDesgner的数 ...

  6. java微信开发之接受消息回复图片或者文本

    上回说到 接口连接成功,接下来是真正的开发了. 消息的接收,整个过程就是关注订阅号的用户在微信订阅号中发送消息,微信服务器接收到消息,将消息发给开发者的服务器,服务器接收消息然后可以根据内容进行回复. ...

  7. 假如 GFW 遇上 ML

    我稍微试了一下梯子 我稍微试了一下梯子,在有梯子的情况下进行google搜索,然后wireshark 抓包.所有问题跃然纸上 当前我认为:> 只要你和一个非国内的服务器长时高频交换数据,基本上就 ...

  8. 1001.A+B Format (20)的感受

    这是提交到Github的object-oriented文件夹里面的代码:https://github.com/sonnypp/object-oriented/tree/master/1001. 一.解 ...

  9. java项目 相对路径(本项目的地址)

    File file=new File(""); String abspath=file.getAbsolutePath(); System.out.println(abspath) ...

  10. C语言:一个能自动生成小学四则运算题目的程序

    完成这个程序,半个小时内完成了,这个程序,可以自动生成小学简易的四则运算,提供菜单让用户选择,然后判断加减乘除,判断答对答错的题目个数,用户同时也可以重新选择继续答题或重新选择或退出程序. 源程序: ...