UPD:修正了一些笔误。
思维难度不大,但是挺恶心的。
期望 DP,考虑设计状态。
状态第一维设成考虑到第 个,这个比较显然。为了方便,这里假定当前第 个音符还没打。
然后想一想我们还缺些什么。两个技能都和连击次数有关,第二维给当前连击了 次。发现强判定效果会干扰我们的判断,因此状态第三维给还有 回合的强判定效果。
因此,我们可以定义状态为: 为考虑到第 个音符,当前连击了 次,还有 回合的强判定效果,打完 内所有音符的期望得分。
发现卡片有很多,在 DP 的时候枚举会超时。发现加分卡使用的关键在于连击次数,改判卡使用的关键在于连击次数和持续时间,这几个是和状态相关的。因此我们考虑分别预处理。
对于加分卡的预处理,我们不妨设 为连击 次的期望加分。枚举所有加分卡 ,枚举 的倍数 ,让 加上 。
对于改判卡的预处理,我们不妨设 为在连击 次的前提下获得 回合强判定效果的概率。发现持续时间长的会覆盖持续时间短的,因此当你选了个持续时间为 的之后持续时间小于等于 的选不选都无所谓了。
当然我们不能把持续时间都为 的改判卡的 直接相加,因为你在考虑持续时间为 的改判卡时,有可能选择了持续时间大于 的改判卡,我们要将这种情况排除。
我们可以这样做:将所有改判卡按 降序排序,每次枚举改判卡 ,强制钦定 被第一个选(编号小于 的一个不选)的概率,或者说考虑真正起作用的改判卡是 的概率。这样可以做到不重不漏,用类似预处理加分卡的方法,持续时间为 的改判卡概率加到对应的 里即可。
具体怎么做呢?我们考虑固定连击次数 ,想让 第一个选,等价于 以前的一个不选,并且 选, 以后的随便,概率为 。至于 只要一个都不选即可,概率为 。实现时可以先枚举所有卡片 再枚举 的倍数 作为连击次数,贡献对应算到 和 头上。
最后是 DP 环节。设第 个音符击打结果为 ,根据 讨论:
- 若断连,此时 。
- 若连击,考虑触发卡片,枚举触发卡片后新的 ,此时 。
答案为 。
CODE
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1024;
int n, o, oo;
int a[maxn];
double g[maxn], p[maxn][6], f[maxn][maxn][6];
struct V {
int x;
double y;
int z;
}b[maxn];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> o >> oo;
for (int i = 1; i <= o; i++) {
int x, y, z;
cin >> x >> y >> z;
for (int j = x; j <= n; j += x) {
g[j] += y / 100.0 * z;
}
}
for (int i = 1; i <= oo; i++) {
int x, y, z;
cin >> x >> y >> z;
b[i] = {x, y / 100.0, z};
}
for (int i = 1; i <= n; i++) cin >> a[i];
p[0][0] = 1;
sort(b + 1, b + oo + 1, [](V x, V y){return x.z > y.z;});
for (int i = 1; i <= n; i++) p[i][0] = 1;
for (int o = 1; o <= oo; o++) {
V j = b[o];
for (int i = j.x; i <= n; i += j.x) {
p[i][j.z] += p[i][0] * j.y;
p[i][0] *= 1 - j.y;
}
}
for (int i = n; i; i--) {
for (int j = 0; j < i; j++) {
for (int k = 0; k <= 5; k++) {
if (a[i] == 0 || (a[i] == 1 && !k)) f[i][j][k] += f[i + 1][0][max(k - 1, 0ll)] + a[i];
else {
for (int t = 0; t <= 5; t++) f[i][j][k] += p[j + 1][t] * (f[i + 1][j + 1][max(k - 1, t)]);
f[i][j][k] += 2 * (j + 2) + g[j + 1];
}
}
}
}
cout << fixed << setprecision(8) << f[1][0][0];
return 0;
}
/*
There is no end though there is a start in space. ---Infinity.
It has own power, it ruins, and it goes though there is a start also in the star. ---Finite.
Only the person who was wisdom can read the most foolish one from the history.
The fish that lives in the sea doesn't know the world in the land.
It also ruins and goes if they have wisdom.
It is funnier that man exceeds the speed of light than fish start living in the land.
It can be said that this is an final ultimatum from the god to the people who can fight.
*/欢迎找错,欢迎 hack。