結果
問題 | No.2955 Pizza Delivery Plan |
ユーザー |
![]() |
提出日時 | 2024-11-08 22:36:11 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 798 ms / 2,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 1,448 ms |
コンパイル使用メモリ | 119,864 KB |
実行使用メモリ | 77,568 KB |
最終ジャッジ日時 | 2024-11-08 22:36:26 |
合計ジャッジ時間 | 12,471 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <iostream>#include <vector>#include <cmath>#include <algorithm>using namespace std;int main(){int n, c;cin >> n >> c;++n;vector<int> x(n), y(n);for (int i = 1; i < n; ++i) cin >> x[i] >> y[i];vector<vector<vector<double>>> dp(1 << n, vector<vector<double>> (n, vector<double> (c + 1, 1e300)));dp[1][0][c] = 0;for (int i = 0; i < 1 << n; ++i){for (int k = 0; k <= c; ++k) dp[i][0][c] = min(dp[i][0][k], dp[i][0][c]);for (int j = 0; j < n; ++j){if (!(i & (1 << j))) continue;for (int k = c; k > 0; --k){for (int l = 0; l < n; ++l){int id = (i | (1 << l));dp[id][l][k - 1] = min(dp[id][l][k - 1], dp[i][j][k] + hypot(x[l] - x[j], y[l] - y[j]));}}for (int k = 0; k <= c; ++k) dp[i | 1][0][c] = min(dp[i | 1][j][k] + hypot(x[j] - x[0], y[j] - y[0]), dp[i | 1][0][c]);}}double ans = dp[(1 << n) -1][0][c];printf("%.10f\n", ans);}