# UVa 10496-collecting beepers

Source: Internet
Author: User

Title: A robot from a starting point (only up, down, left, right movement), after some points back to the starting point, the total path to the minimum length.

Analysis: Graph theory, search. The distance between two points is: ABS (X1-X2) + ABS (Y1-Y2), each point must pass at least once.

If there is a point to go through many times, then he must be in the other two points between the path, then this point can not go through so many times;

Therefore, we only consider the situation of each point after one time (there may be a point on a two-point path), to find the whole arrangement, enumerate the optimal solution.

Description: The origin of overconfidence is inferiority ╮(╯▽╰)╭.

`#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std;int save[3628800][11],temp[11],used[11],count;void dfs (int d, int N) {if (d = = N) {for (int i = 0; i < D; + + i) save[count][i] = Temp[i]; Count ++;return;} for (int i = 0; i < n; + + i) if (!used[i]) {used[i] = 1;temp[d] = I;dfs (d+1, n); Temp[d] = i;used[i] = 0;}} int X[11],y[11];int Main () {int t,n,m,s_x,s_y,d;while (cin >> T) while (T--) {cin >> N >> M >> s_x >> s_y >> d;for (int i = 0; i < D; + + i) Cin >> X[i] >> y[i]; Count = 0;dfs (0, D); int Min = 444444;for (int i = 0; i < Count; + + i) {int dist = ABS (s_x-x[save[i][0]) + ABS (s_y-y[ Save[i][0]]); for (int j = 1; j < D; + + j) Dist + = ABS (X[save[i][j-1]]-x[save[i][j]) + ABS (y[save[i][j-1]]-y[save[i][j ]]);d ist + = ABS (S_x-x[save[i][d-1]]) + ABS (S_y-y[save[i][d-1]); min = min (min, dist);} cout << "the shortest Path has length "<< Min << Endl;} return 0;}`

UVa 10496-collecting beepers

Related Keywords:

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.