Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <string>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #include <set>
- #include <queue>
- #include <map>
- using namespace std;
- const long long inf = 2000000007;
- struct point
- {
- double x, y;
- point(double x, double y) : x(x), y(y) {}
- };
- point operator+(const point &a, const point &b)
- {
- return point(a.x + b.x, a.y + b.y);
- }
- point operator-(const point &a, const point &b)
- {
- return point(a.x - b.x, a.y - b.y);
- }
- double dist(point a, point b)
- {
- return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
- }
- vector<point > p;
- double dp[1000][1000];
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- //freopen("important.in", "r", stdin);freopen("important.out", "w", stdout);
- int n;
- cin >> n;
- double x, y;
- for (int i = 0; i < n; i++)
- {
- cin >> x >> y;
- p.push_back(point(x, y));
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- if (abs(i - j) > 2)
- dp[i][j] = inf;
- for (int i = 0; i < n - 3; i++)
- {
- dp[i][i + 3] = min(dist(p[i], p[i + 2]), dist(p[i + 1], p[i + 3]));
- for (int j = 4; i + j < n; j++)
- {
- for (int k = i + 1; k < i + j; k++)
- dp[i][i + j] = min(dp[i][i + j], dp[i][k] + dp[k][i + j] + dist(p[i], p[k]) + dist(p[k], p[i+j]));
- }
- }
- /*for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- cout << dp[i][j] << " ";
- cout << endl;
- }*/
- cout << fixed;
- cout << setprecision(10) << dp[0][n - 1] << endl;
- //system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement