結果
| 問題 |
No.134 走れ!サブロー君
|
| コンテスト | |
| ユーザー |
assy1028
|
| 提出日時 | 2016-12-23 17:43:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 2,397 bytes |
| コンパイル時間 | 872 ms |
| コンパイル使用メモリ | 100,652 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-14 17:00:23 |
| 合計ジャッジ時間 | 1,537 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;
#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
template<typename T, typename U>
size_t operator()(const pair<T, U> &x) const {
size_t seed = hash<T>()(x.first);
return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int n;
int x[15], y[15];
double w[15];
double wsum = 0;
double s[1<<15];
int d[15][15];
double solve() {
n++;
for (int i = 1; i < n; i++) wsum += w[i];
for (int i = 0; i < 1<<n; i++) {
double t = wsum;
for (int j = 0; j < n; j++) {
if ((i>>j)&1) t -= w[j];
}
s[i] = t;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
d[i][j] = abs(x[i]-x[j]) + abs(y[i]-y[j]);
}
}
double dp[1<<n][n];
for (int i = 0; i < 1<<n; i++) fill(dp[i], dp[i]+n, inf);
dp[1][0] = 0.0;
for (int i = 1; i < n; i++) {
dp[1<<i][i] = d[0][i] * ((wsum+100.0)/120.0) + w[i];
}
for (int i = 2; i < 1<<n; i++) {
for (int j = 0; j < n; j++) {
if ((i>>j)&1) {
for (int k = 0; k < n; k++) {
if (k != j && (i>>k)&1) {
dp[i][j] = min(dp[i][j], dp[i^(1<<j)][k] + d[k][j]*((s[i^(1<<j)]+100.0)/120.0) + w[j]);
}
}
}
}
}
return dp[(1<<n)-1][0];
}
void input() {
cin >> x[0] >> y[0];
cin >> n;
for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> w[i];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
input();
cout << solve() << endl;
}
assy1028