Algorithm title: UVA 10599 Robots (II) (DP Lis)

Source: Internet
Author: User
Tags valid

Your Company provides the can is used to pick up litter from fields after sporting events and concerts. Before are assigned to a job, a aerial photograph of the "field is" marked with a grid. Each location in the grid, that contains garbage is marked. All robots begin with the northwest corner and end their movement the southeast corner. A robot can only move in two directions, either to the east or South. Upon entering a cell that contains garbage, the robot can is programmed to pick it up before proceeding. Once a robot reaches its destination at the southeast corner it cannot to be repositioned or reused. Since your expenses are directly proportional to the number of robots used for a particular job, you are interested in MAK ing the most out of them. Your task would is to use a robot to clean the maximum number of cells containing garbage. Now there can is many ways to does this job, so your task would is to, the number of ways and show us one such sample .

You are your robot can traverse many cells without picking up garbage and so for us a valid solution would is the sequence of The cell numbers that the robot cleans. The robots only clean cells that contain garbage; But can program them to avoid picking up garbage from specific cells, if your would to.

In the figure above we show a field map of that has 6 rows and 7 columns. The cells in a field map are numbered into row major order starting from 1. For the example shown here, the following 7 cells contain garbage: 2 (1,2), 4 (1,4), 11 (2, 4), 13 (2, 6), 25 (4, 4), (4, 7) and (6, 7). Here cells are presented in Cell_number (row, column) format. Now the maximum number of cells this can be cleaned are 5, and there are 4different ways to do:

<2, 4, one, 28>

<2, 4, one, 41>

<2, 4, one, 28>

<2, 4, one, 41>

Input

An input file consists of one or more field maps followed by a line containing -1-1 to signal the end of the INP UT data. The description of a field map starts with the number of rows and the number of columns in the grid. Then in the subsequent lines, the garbage locations follows. The end of a field map was signaled by 0 0. Each garbage location consists's two integers, the row and column, separated by a. The rows and columns are numbered as shown in Figure 1. The garbage locations won't be given in any specific order. And a location would is reported twice for a field map. Please are required to solve, the field map would is at most rows and columns.

Output

The output for each test case is starts with the serial number (starting from 1) for this test case. Then the following integers are listed on a line: N –the Maximum number of cells this robot can clean, C –the number of ways that those N cells can be cleaned, and n numbers describing one possible sequ ence of cell numbers that the robot would clean. As there can be C different such sequences and we are asking to only one sequence any valid sequence do. Make sure so all this 2+n integers for the A test case are printed in a single line. There must be one spaces separating two consecutive integers and a space between the colon and the The E. The sample output format for a clear idea.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.