結果
問題 | No.2955 Pizza Delivery Plan |
ユーザー |
|
提出日時 | 2024-11-08 22:07:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 124 ms / 2,000 ms |
コード長 | 2,638 bytes |
コンパイル時間 | 2,214 ms |
コンパイル使用メモリ | 206,576 KB |
最終ジャッジ日時 | 2025-02-25 02:49:06 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h>using namespace std;template<typename T>struct Point{public:T x,y;Point() : x(0),y(0) {}Point(T a,T b) : x(a),y(b) {}Point &operator=(const Point &b) = default;Point operator+(const Point &b){return Point(x+b.x,y+b.y);}Point operator-(const Point &b){return Point(x-b.x,y-b.y);}Point operator+=(const Point &b){return *this=*this+b;}Point operator-=(const Point &b){return *this=*this-b;}bool operator==(const Point &b){return x==b.x && y==b.y;}bool operator!=(const Point &b){return x!=b.x || y!=b.y;}bool operator<(const Point &b){if(x == b.x) return y < b.y;else return x < b.x;}bool operator<=(const Point &b){return (*this) < b || (*this) == b;}bool operator>(const Point &b){return !((*this) <= b);}bool operator>=(const Point &b){return !((*this) < b);}friend T inner(const Point a,const Point b){return a.x*b.x+a.y*b.y;}friend T cross(const Point a,const Point b){return a.x*b.y-a.y*b.x;}friend T twodist(const Point a,const Point b){return sqrtl((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}};template<typename T>istream &operator>>(istream &is,Point<T> &a){is >> a.x >> a.y;return is;}template<typename T>ostream &operator<<(ostream &os,Point<T> &a){os << a.x << " " << a.y;return os;}int main(){ios_base::sync_with_stdio(false);cin.tie(nullptr);int N,K; cin >> N >> K;vector<Point<double>> P(N);for(auto &p : P) cin >> p;int n2 = 1<<N;vector<vector<vector<double>>> dp(n2,vector<vector<double>>(N,vector<double>(K,1e100)));for(int i=0; i<N; i++) dp.at(1<<i).at(i).at(K-1) = twodist({0.0,0.0},P.at(i));for(int i=1; i<n2; i++){for(int k=0; k<N; k++){if(!(i&(1<<k))) continue;int left = i-(1<<k);for(int l=0; l<N; l++){if(!(i&(1<<l))) continue;double mind = dp.at(left).at(l).at(0);for(int m=0; m<K-1; m++){dp.at(i).at(k).at(m) = min(dp.at(i).at(k).at(m),dp.at(left).at(l).at(m+1)+twodist(P.at(k),P.at(l)));mind = min(mind,dp.at(left).at(l).at(m+1));}dp.at(i).at(k).at(K-1) = min(dp.at(i).at(k).at(K-1),mind+twodist({0,0},P.at(l))+twodist({0,0},P.at(k)));}}}double answer = 1e100;for(int i=0; i<N; i++){double nowd = twodist({0,0},P.at(i));for(int k=0; k<K; k++) answer = min(answer,dp.at(n2-1).at(i).at(k)+nowd);}cout << fixed << setprecision(20) << answer << endl;}