Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя luyuncheng

Автор luyuncheng, 11 лет назад, По-английски

For this question:codeforces 201B Lucky Common Subsequence。 it ask us just one virus so we can use kmp + dp to solve this question。

but i have a question that if ask us more than one virus what should i do?? i have an ideal just use Aho-Corasick automaton to get fail array but i do not know how to set dp array?

Can anyone help me ?

Thanks in advance!!

  • Проголосовать: нравится
  • -11
  • Проголосовать: не нравится

»
11 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Assign an index to each AC node and represent the fail transitions accordingly.

Instead of having a DP array dp[s1 length][s2 length][virus length], you'll have dp[s1][s2][y] and it is calculated using dp[s1-1][s2][y], dp[s1][s2-1][y], and dp[s1-1][s2-1][x] for all x that have a fail transition from AC node y to AC node x.

  • »
    »
    11 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thanks a lot. but i want to know what ac node record? Record whether it visited by some virus??

    • »
      »
      »
      11 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      ac node is just the stage of string matching. The number of ac nodes is at most (sum of all lengths of accept strings). In this case you need to build the automaton with multiple 'accept' stages.

      • »
        »
        »
        »
        11 лет назад, # ^ |
          Проголосовать: нравится -6 Проголосовать: не нравится

        额。。那个可以用中文不?ac节点是表示字符匹配的状态呗?那么假设题意是对于任意virus,都不能以子串的形式出现,那么我对应ac自动机里trie树上每个节点应该存什么?