zoukankan      html  css  js  c++  java
  • BZOJ 2580: [Usaco2012 Jan]Video Game

    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

  • 相关阅读:
    Vue Cli3.0 使用jquery
    使用js加载器动态加载外部js、css文件
    通过js获取本机的IP地址
    $.ajax 中的contentType类型
    vue中 :style 与 :class 三元运算符使用
    bootstrap table checkbox获得选中得数据
    vscode自动生成文件头部注释和函数注释
    axios二次封装的几种方法
    vue组件库element-ui 的Table内容显示不更新
    Linux中iptables设置详细
  • 原文地址:https://www.cnblogs.com/yousiki/p/6412228.html
Copyright © 2011-2022 走看看