程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> each-Walk the Talk

each-Walk the Talk

編輯:編程解疑
Walk the Talk

Description

Farmer John has set up a puzzle for his cows to solve. At the entrance to the barn, he has laid out an H x W (1 <= H <= 30, 1 <= W <= 30) grid of letters. Before a cow can enter the barn, she must spell out a valid English word by jumping from square to square, creating a sequence of letters. She can start at any square but may only jump to a subsequent square that is located to the right and/or above the current square (i.e., neither to the left nor lower). The next square can be any distance from the current one since the cows are world-class jumpers!

No two cows may traverse the exact same path, although two cows are allowed to spell the same word via different paths.

As an example, consider this grid (presuming 'TO' and 'OX' are words):

T X X O
T X Q T
X T X Q

Four paths are valid, all spelling 'TO' (one spelling requires a 'T' from the bottom row and an 'O' from the top row). 'OX' is a valid word, but would require jumping to an 'X' square left of the 'O', which is not allowed.

Given the grid and a list of valid words, compute the number of cows that can enter the barn without any cow repeating a path. See a copy of the list here.
Input

  • Line 1: Two integers: H and W

  • Lines 2..H+1: Each line contains W characters, without spaces, representing a row in the grid. The first row is the top row.The first character in each row is the left-most character.

  • Line H+2: A blank line

  • Line H+3..: The list of valid words
    Output

  • Line 1: The number of cows that can enter the barn without repeating a path.
    Sample Input

3 4
TXXO
TXQT
XTXQ

A
AA
AAA
...
Sample Output

4

最佳回答:


http://www.cppblog.com/varg-vikernes/archive/2010/04/09/112088.aspx

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved