当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2929:The Traveling Salesman

题目描述

For thousands of years, salesmen have faced the problem of touring sites for potential customers, visiting each site exactly once, and minimizing the total cost of this tour. In the old days, these sites were towns spread out throughout the country, and the salesman had to travel the rickety, crooked roads that connected the towns. But now, in 2030, cities and have modernized and grown, so a salesman typically stays within the same city. Furthermore, modern cities are laid out in a grid-like pattern of tall skyscrapers, with sky bridges joining some pairs of adjacent skyscrapers on all floors.

The salesman has determined which floor of each skyscraper contains the most potential customers and will only visit the best floor of each skyscraper. Now the salesman must plan his course. Starting on the ground floor (floor 0) of the skyscraper in the northwest corner of the grid, the salesman must visit the specified best floor of each skyscraper before returning to the ground floor of either of the skyscrapers at the southwest, southeast, or northeast corners. In order to travel between floor 10 of one skyscraper and floor 6 of an adjacent skyscraper, the salesman first takes the sky bridge across to floor 10 of the adjacent skyscraper and then takes an elevator down 4 floors. Of course, because the salesman’s time is precious, he wants to minimize the total number of floors he must travel by elevator. For example, if his tour involves traveling from floor 3 to 8 to 5 to 10, the number of floors traveled by elevator is (8 − 3) + (8 − 5) + (10 − 5) = 13.

To make the salesman’s life (and yours) more difficult, some sky bridges do not exist between two adjacent skyscrapers, and in that case, obviously the salesman cannot fly across the gap.

Because modern cities are much larger than the small towns that salesmen dealt with generations ago, our salesman needs a plan so that he does not lose his bearings and visit a skyscraper more than once (in which case he will get beaten by the people for pestering them so much) or less than once (in which case he might have lost profit). To that end, the salesman has decided to only consider tours similar to the one in the figure. The salesman starts at the northwest corner, and either goes south or east for any distance (as long as all sky bridges exist along that path). Then, he turns towards away from the edge of the city and travels to the adjacent skyscraper, and turns again, heading back opposite the initial direction. After any amount of zig-zagging, the salesman can choose to switch over to zig-zagging in the other orientation.

Given the floors of each skyscraper in the city that the salesman wishes to visit and which sky bridges do not exist, compute the minimum number of floors that the salesman must travel on a tour that meets the above criteria. Also, print out the number of possible tours achieving that minimum.

输入解释

The first line contains two numbers M (1 ≤ M ≤ 1000) and N (1 ≤ N ≤ 1000), the dimensions of the city. Each of the next M lines contains N integers in the range [0, 100]. Each integer is the floor that the salesman must visit. Optionally following each integer might be a token specifying that some sky bridges do not exist. Suppose you just read the floor for location (x, y) (note that (0, 0) is the northwest corner, (N − 1, 0) is the northeast corner, (0, M − 1) is the southwest corner, and (N − 1, M − 1) is the southeast). If the token is x, no sky bridges exist between (x, y) and (x + 1, y). If the token is y, no sky bridges exist between (x, y) and (x, y + 1). All tokens and integers are separated by a single space.

输出解释

If there is no tour, print No solution. Otherwise, print out the number of tours and the minimum number of floors travelled.

输入样例
2 4
0 y 10 20 30
5 8 25 28
输出样例
1 tours, traveling a minimum of 60 total floors

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2929

最后修改于 2020-10-29T06:47:50+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000 65536