Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstdio>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <queue>
- #include <cassert>
- #define PB push_back
- #define MP make_pair
- #define sz(v) (ll((v).size()))
- #define forn(i,n) for(ll i = 0; i < (n); ++i)
- #define forv(i,v) forn(i,sz(v))
- #define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
- #define all(v) (v).begin(), (v).end()
- using namespace std;
- typedef long long ll;
- typedef pair<ll, ll> pii;
- typedef vector<ll> vi;
- typedef vector<vi> vvi;
- const int N = 1000010;
- ll m, n, k;
- map<pair<ll, ll> , double> memo;
- map<ll, vector< pair<ll, pair<int, double> > > > depart[N];
- ll next(ll city, ll t) {
- auto ans = depart[city].lower_bound(t + 1);
- return ans == depart[city].end() ? k : ans->first;
- }
- double dp(ll src, ll t) {
- if (memo.find(MP(src, t)) != memo.end()) return memo[MP(src, t)];
- if (t == k) return (src == 1 ? 1.0 : 0.0);
- // iterate all starting at t
- double ans = dp(src, next(src, t));
- double stay = ans;
- for (auto tri : depart[src][t]) {
- auto key = tri.second;
- double take = dp(tri.first, next(tri.first, tri.second.first));
- ans = max(ans, take * tri.second.second + stay * (1 - tri.second.second));
- }
- //cerr << src << " " << t << " " << ans << endl;
- return memo[MP(src, t)] = ans;
- }
- int main() {
- ios::sync_with_stdio(0); cin.tie(0);
- cin >> m >> n >> k;
- forn(i, m) {
- ll p1, p2, t1, t2; double prob;
- cin >> p1 >> p2 >> t1 >> t2 >> prob;
- depart[p1][t1].reserve(1);
- depart[p1][t1].PB( MP(p2, MP(t2, prob)) );
- }
- cout.precision(10);
- cout << dp(0, next(0, -1)) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement