题目链接:
Hunter
问题描述
One day, a hunter named James went to a mysterious area to find the treasures. James wanted to research the area and brought all treasures that he could.
The area can be represented as a N*M rectangle. Any points of the rectangle is a number means the cost of research it,-1 means James can't cross it, James can start at any place out of the rectangle, and explore point next by next. He will move in the rectangle and bring out all treasures he can take. Of course, he will end at any border to go out of rectangle(James will research every point at anytime he cross because he can't remember whether the point are researched or not). Now give you a map of the area, you must calculate the least cost that James bring out all treasures he can take(one point up to only one treasure).Also, if nothing James can get, please output 0.
输入
The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case begins with a line containing 2 integers N M , (1<=N,M<=200), that represents the rectangle. Each of the following N lines contains M numbers(0~9),represent the cost of each point. Next is K(1<=K<=13),and next K lines, each line contains 2 integers x y means the position of the treasures, x means row and start from 0, y means column start from 0 too.
输出
For each test case, you should output only a number means the minimum cost.
样例输入
2
3 3 3 2 3 5 4 3 1 4 2 1 1 1 3 3 3 2 3 5 4 3 1 4 2 2 1 1 2 2
样例输出
8
11
题意
给你一个n*m的迷宫,每个方格上标的是花费,现在有些坐标上有宝藏,你可以从边界的方格进入,最后需要从边界处离开,问你获得所有宝藏的最小花费,每个点可以重复走。
题解
构造一个超级节点,点权为0,与所有的边界相连。然后对所有的宝藏的点跑最短路。
重新构造只有宝藏和超级节点的图,任意两个点之间的路径为上面处理出来的最短路。 对于新图跑下TSP就ok啦。
代码
#include