Gym - 101190D Delight for a Cat

Description

\(n\) 个小时,每个小时要么打隔膜要么睡觉,第 \(i\) 个小时,睡觉的愉悦值为 \(s_i\) ,打隔膜的愉悦值为 \(e_i\) ,对于任意一段连续的 \(k\) 小时,必须至少有 \(m_s\) 时间在睡觉, \(m_e\) 时间在打隔膜。求最大愉悦值。

Solution

如果令所有的时间都打隔膜,则在 \(i\) 时刻睡觉的收益就是 \(s_i-e_i\) 。令第 \(i\) 时刻是否睡觉的状态为 \(x_i\) ,则

\[t1\le x_i+x_{i+1}+x_{i+2}+\cdots +x_{i+k-1}\le k-t2 \]

要最大化

\[\sum_{i=1}^n x_i\times (s_i-e_i) \]

添加新变量 \(y,z\in [0,+\infty]\) 。有方程组

\[\begin{cases} x_1+x_2+\cdots +x_k=m_s+y_1\\ x_1+x_2+\cdots +x_k=k-m_e-z_1\\ x_2+x_3+\cdots +x_{k+1}=m_s+y_2\\ x_2+x_3+\cdots +x_{k+1}=k-m_e-z_2\\ \cdots \\ x_{n-k+1}+x_{n-k+2}+\cdots +x_n=m_s+y_{n-k+1}\\ x_{n-k+1}+x_{n-k+2}+\cdots +x_n=k-m_e-z_{n-k+1}\\ 0=0 \end{cases} \]

差分一下

\[\begin{cases} x_1+x_2+\cdots +x_k=m_s+y_1\\ y_1+z_1=(k-m_e-m_s)\\ x_{k+1}+(k-m_e-m_s)=x_1+y_2+z_1\\ y_2+z_2=(k-m_e-m_s)\\ \cdots\\ y_{n-k+1}+z_{n-k+1}=(k-m_e-m_s)\\ k-m_e=x_{n-k+1}+x_{n-k+2}+\cdots +x_n+z_{n-k+1} \end{cases} \]

每个变量在等式左右各出现一次,故等式看成点,左边看作流出,右边看作流入。对于每个 \(x\) 变量,流出往流出连边,流量为 \(1\) 费用为 \(s_i-e_i\) 。对于 \(y\)\(z\) ,流量为 \(+\infty\) ,费用 \(0\) 。对于常数,流出连向 \(T\) ,流入从 \(S\) 连,流量为常数的值,费用为 \(0\)

最后答案为最大费用最大流。

posted @ 2018-06-13 10:31  aziint  阅读(203)  评论(0编辑  收藏  举报
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.