编程介的小学生 2016-11-25 15:31 采纳率: 20.5%
浏览 930
已采纳

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

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-11-25 15:54
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误