Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int a[14], b[14], n, ans;
- vector<int>seen;
- void solve(int cur, int ind, int cost){
- if(ind == n){
- int x = abs(a[cur] - a[1]) + abs(b[cur]-b[1]);
- ans = min(ans, x+cost);
- return;
- }
- for(int i = 2; i < n+2; i++){
- if(seen[i] == 0){
- seen[i] = 1;
- solve(i, ind+1, cost + abs(a[cur]-a[i]) + abs(b[cur] - b[i]));
- seen[i] = 0;
- }
- }
- }
- int main(){
- int tc=10, cases=1;
- while(tc--){
- cin >> n;
- seen.assign(n+2, 0);
- for(int i = 0; i < n + 2; i++){
- cin >> a[i] >> b[i];
- }
- ans = INT_MAX;
- solve(0, 0, 0);
- cout << "# "<< cases++ <<" " << ans << endl;
- }
- }
- /*5
- 0 0 100 100 70 40 30 10 10 5 90 70 50 20
- 6
- 88 81 85 80 19 22 31 15 27 29 30 10 20 26 5 14
- 5
- 0 0 100 100 70 40 30 10 10 5 90 70 50 20
- 6
- 88 81 85 80 19 22 31 15 27 29 30 10 20 26 5 14
- 5
- 0 0 100 100 70 40 30 10 10 5 90 70 50 20
- 6
- 88 81 85 80 19 22 31 15 27 29 30 10 20 26 5 14
- 5
- 0 0 100 100 70 40 30 10 10 5 90 70 50 20
- 6
- 88 81 85 80 19 22 31 15 27 29 30 10 20 26 5 14
- 5
- 0 0 100 100 70 40 30 10 10 5 90 70 50 20
- 6
- 88 81 85 80 19 22 31 15 27 29 30 10 20 26 5 14
- # 1 200
- # 2 304
- # 3 200
- # 4 304
- # 5 200
- # 6 304
- # 7 200
- # 8 304
- # 9 200
- # 10 304
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement