結果
問題 | No.134 走れ!サブロー君 |
ユーザー |
![]() |
提出日時 | 2018-05-03 00:40:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 5,000 ms |
コード長 | 1,636 bytes |
コンパイル時間 | 1,529 ms |
コンパイル使用メモリ | 167,520 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-06-28 00:28:27 |
合計ジャッジ時間 | 2,228 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include <bits/stdc++.h>//#define int long longusing namespace std;using LL = long long;using P = pair<int, int>;using Tapris = tuple<int, int, int>;#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)#define REP(i, n) FOR(i, 0, n)#define pb(a) push_back(a)#define all(x) (x).begin(),(x).end()const int INF = (int)1e9;const LL INFL = (LL)1e15;const int MOD = 1e9 + 7;int dy[]={0, 0, 1, -1, 0};int dx[]={1, -1, 0, 0, 0};/*************** using variables ***************/int n, x[105], y[105];double w[105];double dp[1 << 15][15];double weight[1 << 15];/**********************************************/bool contain(int mask, int pos){return (mask & (1 << pos)) != 0;}signed main(){cin.tie(0);ios::sync_with_stdio(false);cin >> x[0] >> y[0] >> n;w[0] = 0.0;REP(i, n) cin >> x[i+1] >> y[i+1] >> w[i+1];for(int mask = 0; mask < (1 << (n + 1)); ++mask){double tmp = 0;for (int i = 0; i < n + 1; i++){if(!contain(mask, i)){tmp += w[i];}}weight[mask] = tmp;}REP(i, (1 << 15)) REP(j, 15) dp[i][j] = INF;dp[0][0] = 0;for(int mask = 0; mask < (1 << (n + 1)); mask++){REP(i, n+1){REP(p, n+1) if(!contain(mask, p)){double cost = (abs(x[i] - x[p]) + abs(y[i] - y[p])) * (weight[mask] + 100.0) / 120.0;dp[mask | (1 << p)][p] = min(dp[mask | (1 << p)][p], dp[mask][i] + cost);}}}double totalw = 0;REP(i, n+1) totalw += w[i];printf("%.9f\n" ,dp[(1 << (n+1)) - 1][0] + totalw);}