結果
問題 | No.2955 Pizza Delivery Plan |
ユーザー |
![]() |
提出日時 | 2024-11-08 23:28:24 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 371 ms / 2,000 ms |
コード長 | 1,466 bytes |
コンパイル時間 | 2,234 ms |
コンパイル使用メモリ | 211,472 KB |
実行使用メモリ | 63,488 KB |
最終ジャッジ日時 | 2024-11-08 23:28:48 |
合計ジャッジ時間 | 7,995 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}int main() {fast_io();int n, k;cin >> n >> k;vector<pair<int, int>> xy(n);for (int i = 0; i < n; i++) {cin >> xy[i].first >> xy[i].second;}using ld = long double;vector<vector<ld>> dist(n, vector<ld>(n));vector<ld> dist_org(n);for (int i = 0; i < n; i++) {dist_org[i] = hypotl(xy[i].first, xy[i].second);for (int j = 0; j < n; j++) {dist[i][j] =hypotl(xy[i].first - xy[j].first, xy[i].second - xy[j].second);}}vector<vector<vector<ld>>> dp(1 << n,vector<vector<ld>>(n, vector<ld>(k, 9e18)));for (int i = 0; i < n; i++) {dp[1 << i][i][k - 1] = dist_org[i];}for (int st = 0; st < (1 << n); st++) {for (int cur = 0; cur < n; cur++) {for (int rem = 0; rem < k; rem++) {for (int nxt = 0; nxt < n; nxt++) {if (st & (1 << nxt)) continue;if (rem > 0) {dp[st | (1 << nxt)][nxt][rem - 1] =min(dp[st | (1 << nxt)][nxt][rem - 1],dp[st][cur][rem] + dist[cur][nxt]);}dp[st | (1 << nxt)][nxt][k - 1] =min(dp[st | (1 << nxt)][nxt][k - 1],dp[st][cur][rem] + dist_org[nxt] + dist_org[cur]);}}}}ld ans = 9e18;for (int cur = 0; cur < n; cur++) {for (int rem = 0; rem < k; rem++) {ans = min(ans, dp[(1 << n) - 1][cur][rem] + dist_org[cur]);}}cout << setprecision(16) << fixed << ans << endl;}