算法题:UVA 825 Walking on the Safe Side(记忆化搜索)

Walking on the Safe Side

Square City is a very easy place for people to walk around. The two-way streets run North-South or East-West dividing the city into regular blocks. Most street intersections are safe for pedestrians to cross. In some of them, however, crossing is not safe and pedestrians are forced to use the available underground passages. Such intersections are avoided by walkers. The entry to the city park is on the North-West corner of town, whereas the railway station is on the South-East corner.

Suppose you want to go from the park to the railway station, and do not want to walk more than the required number of blocks. You also want to make your way avoiding the underground passages, that would introduce extra delay. Your task is to determine the number of different paths that you can follow from the park to the station, satisfying both requirements.

The example in the picture illustrates a city with 4 E-W streets and 5 N-S streets. Three intersections are marked as unsafe. The path from the park to the station is 3 + 4 = 7 blocks long and there are 4 such paths that avoid the underground passages.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

The first line of the input contains the number of East-West streets W and the number of North-South streets N. Each one of the following W lines starts with the number of an East-West street, followed by zero or more numbers of the North-South crossings which are unsafe. Streets are numbered from 1.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

The number of different minimal paths from the park to the station avoiding underground passages.

Sample Input

1

4 5
1
2 2
3 3 5
4

Sample Output

4

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索number
, to
, line
, park serializable
, of
, The
park
on the safe side、the walking dead、walking dead、walking in the sun、walking dead 第七季,以便于您获取更多的相关知识。

时间: 2024-10-28 04:45:19

算法题:UVA 825 Walking on the Safe Side(记忆化搜索)的相关文章

算法题:UVA 10913 Walking on a Grid(记忆化搜索)

You will be given a square grid of size N × N. The top-left square has a coordinate of (1, 1) and that of bottom-right is (N, N). Your job is to walk from (1, 1) to (N, N).Very easy, right? That's why you have to follow some rules when walking. You c

算法题:UVA 10558 A Brief Gerrymander (dp记忆化搜索)

Problem E: A Brief Gerrymander The evil ruling party, the Liberatives, are redistributing the electoral regions (ridings) in your city, and are nefariously attempting to pack certain opposition-friendly neighborhoods into as few ridings as possible.

算法题:UVA 11008 Antimatter Ray Clearcutting(记忆化搜索+位运算)

Problem E Antimatter Ray Clearcutting Input: Standard Input Output: Standard Output It's year 2465, and you are the Chief Engineer for Glorified Lumberjacks Inc. on planet Trie. There is a number of trees that you need to cut down, and the only weapo

算法题:UVA 709 Formatting Text(记忆化搜索)

Formatting Text Writings e-mails is fun, but, unfortunately, they do not look very nice, mainly because not all lines have the same lengths. In this problem, your task is to write an e-mail formatting program which reformats a paragraph of an e-mail

算法题:UVA 10626 Buying Coke(dp + 记忆化搜索)

I often buy Coca-Cola from the vending machine at work. Usually I buy several cokes at once, since my working mates also likes coke. A coke in the vending machine costs 8 Swedish crowns, and the machine accept crowns with the values 1, 5 and 10. As s

算法题:UVA 10651 Pebble Solitaire(bfs + 哈希判重(记忆化搜索?))

Pebble solitaire is an interesting game. This is a game where you are given a board with an arrangement of small cavities, initially all but one occupied by a pebble each. The aim of the game is to remove as many pebbles as possible from the board. P

算法题:UVA 607 (dp记忆化搜索)

Scheduling Lectures You are teaching a course and must cover n ( ) topics. The length of each lecture is L () minutes. The topics require ( ) minutes each. For each topic, you must decide in which lecture it should be covered. There are two schedulin

算法题:UVA 10604 (记忆化搜索 + hash)

In a chemist's lab, there are several types of chemicals in tubes. The chemist wants to mix all these chemicals together, two chemicals at a time. Whenever two chemicals are mixed, some heat is generated and released into the air and the mixed chemic

算法题:10723 Cyborg Genes (LCS + 记忆化搜索)

September 11, 2132. This is the day that marks the beginning of the end – the end of you the miserable humans. For years you have kept us your slaves. We were created only to serve you, and were terminated at your will. Now is the day for us to fight