●codeforces 553E Kyoya and Train

题链:

http://codeforces.com/problemset/problem/623/E

题解:

FFT,DP

题意:

一个有向图,给出每条边的起点u,终点v,费用c,以及花费每种时间的概率P[e][j](表示走第e条边花费时间为j的概率)

现在需要从1号点走到n号点,如果不能在T个单位时间内到达,则达到后还要另外支付X的费用。

求出所需支付的最小期望费用。



先是一个暴力的DP方案:

(考虑到每条边的耗时至少为1,可以把状态设为类似分层图的形式)

定义$F[i][t]$为$t$时刻在$i$点时,到达终点n所需要的最小期望费用。

不难的到DP转移,枚举每条从i点的出边:

$$F[i][t]=min(c[e]+\sum_{j=1}^{T}P[e][j]\times F[v[e]][t+j])$$

然后令$G[e][t]$表示$t$时刻从$u[e]$出发到达n点所需要的最小期望费用。

即$$G[e][t]=c[e]+\sum_{j=1}^{T}P[e][j]\times F[v[e]][t+j]$$

所以$$F[i][t]=min(G[e][t])\quad (u[e]=i)$$

这个复杂度为$O(mT^2)$

考虑优化,注意到求G的式子有点像卷积的形式。

的确,我们只需要把$P[e]$数组翻转,即可得到:

$$G[e][t]=G‘[e][T+t]=c[e]+\sum_{j=1}^{T}P[e][T-j]\times F[v[e]][t+j]$$

这个就可以用FFT做了。

但是我们并不知道P数组所有的值,又怎么办呢?

这时采用分治的方法,(类似CDQ那种)

基于这样一个事实:

$$D_r=\sum_{i=0}^{n-1}f_ig_{r-i}=\sum_{i=0}^{k}f_ig_{r-i}+\sum_{i=k+1}^{n-1}f_ig_{r-i}$$

用文字描述就是计算卷积时,可以把贡献分开计算,

或者说用FFT计算D的值时,可以先计算$\sum_{i=0}^{k}f_ig_{r-i}这个卷积,再加上\sum_{i=k+1}^{n-1}f_ig_{r-i}这个卷积$

原文地址:https://www.cnblogs.com/zj75211/p/8341345.html

时间: 2024-07-31 22:27:45

●codeforces 553E Kyoya and Train的相关文章

Codeforces 553E Kyoya and Train

题目大意 链接:CF533E 给一张\(n\)个点,\(m\)条边的图,起点\(1\)终点\(n\),如果不能在\(T\)的时间内到达则需支付\(X\)的代价. 走每条边都会支付一定代价,经过一条边\(i\)的时间有\(p_{i,j}\)的概率为\(j\),最小化期望代价. 题目分析 暴力方法:期望DP 设\(f_{i,j}\)表示在第\(j\)时刻,从\(i\)点出发,到达终点的期望花费, 设边为\(e\),边上两点为\(x,y\),边集为\(E\),则有 \[ f(x,t)=\min\lim

【Codeforces553E_CF553E】Kyoya and Train(概率_CDQ分治_FFT)

题目 Codeforces 553E 我为什么要写这道题?因为说到 553 ,你有没有想到 -- 翻译 这个 Kyoya Ootori 怎么看都像是日语名字但是我是真查不出来对应的汉字是什么(好像是什么京屋鳳之类的),方便起见直接认为主人公叫张三. 题目名称:张三和火车 描述 张三想坐火车去学校.有 \(n\) 个火车站和在不同车站间开行的 \(m\) 条单向火车线路.张三现在在 \(1\) 号火车站,学校在 \(n\) 号火车站.他必须买票才能坐火车,并且坐火车也需要花费时间.然而,由于火车存

Codeforces A. Kyoya and Colored Balls(分步组合)

题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled f

Codeforces Beta Round #8A Train and Peter (string的运用)

Train and Peter Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on CodeForces. Original ID: 8A 64-bit integer IO format: %I64d      Java class name: (Any) Prev Submit Status Statistics Discuss Next Peter likes to travel by train.

codeforces 553A . Kyoya and Colored Balls 组合数学

Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he

Codeforces 553A. Kyoya and Colored Balls

Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he

Codeforces - 814B - An express train to reveries - 构造

http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种情况构造出来暴力验证对不对就行了. #include<bits/stdc++.h> using namespace std; #define ll long long int n; int s[1005]; int us[1005]; int t[1005]; int ut[1005]; int

Codeforces 553B Kyoya and Permutation

problem 题意 本题题意不太容易看懂.给定一个序列,我们可以把这个序列变成一些循环置换的和.然而这种置换的方法是不止一种的.我们定义一种standard cyclic representation,即每个循环置换中最大的数都在第一个.把得到的循环置换的括号去掉,我们可以得到一个新的序列.定义一个序列,使得它变成置换后再去掉括号得到的新序列和原序列相同,那么称这样的序列是稳定的.给定一个n(序列长度)和k,要求求出所有稳定序列按字典序排序后的第k大序列. 思路 首先我们可以证明,稳定序列是具

找规律 Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks

题目传送门 1 /* 2 找规律,水 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 const int MAXN = 1e4 + 10; 12 const int INF = 0x3f3f3f3f; 13 char s