• [H] Wanted

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • The movie "Wanted" is very wonderful. A killer will kill one people by the name appeared at the cloth which is weaved by the Fate Loom.


    One day, the rule of the Fate Loom is changed:
    The cloth wide N and long M. Each unit of the cloth represent one English letter.
    So there are lots of strings - each row or each column is a string.

    For example:

    googl
    baidu
    tence
    alibb
    acmer
    is a cloth, and its strings of each row are:
    googl, baidu, tence, alibb, acmer
    its strings of each column are:
    gbtaa, oaelc, oinim, gdcbe, luebr

    And there are some names of person who should be killed.
    You have to pay attention to that each letter on each row or each column must be a part of a name, or that whole row or column will be ignored.

    For example:
    One line is 'googl' and names are 'goo' and 'gl', so it's valid.
    But if the names are 'goo' and 'gle', the line 'googl' will be ignored because 'goo' and 'gle' can't spell out 'googl'.

    You should write a program that can calculate out how many valid rows and columns on the cloth.
  • 输入
  • This problem contains several cases.
    The first line of each case is two integers N and M. (0 < N, M <= 500)
    Then follows the cloth N * M. (The cloth only contains the lowercase letters)
    The next line is a integer X. (0 < X <= 1000)
    Next X lines contain X names who will be killed. (Each name is not exceed 30)
  • 输出
  • For each case, you should output the number of valid rows and columns.
  • 样例输入
  • 5 5
    googl
    oaidu
    oence
    glibb
    lcmer
    4
    go
    oa
    idu
    elc
    
  • 样例输出
  • 2
    
  • 提示
  • 来源
  • XadillaX
  • 操作

显示春菜