您的位置:首页 > 其它

Codeforces 601C Kleofáš and the n-thlon(dp)

2015-12-03 21:33 417 查看
题目链接:Codeforces 601C Kleofáš and the n-thlon

解题思路

dp[i][j]表示到第i场比赛时,得分为j的人数期望。dp[i][j] = sum { dp[i-1][j-x] ~ dp[i-1][j-x] | 1 ≤ x ≤ m && x != rank[i] }

代码

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 2 * 1e5 + 5;

int N, M, X[105];
double dp[2][maxn];

int main () {
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i++) scanf("%d", &X[i]);
if (M == 1)
printf("%.10lf\n", 1.0);
else {

int nw = 0, nx = 1, s = 0;
memset(dp[nx], 0, sizeof(dp[nx]));
dp[nx][0] = M - 1;

for (int i = 1; i <= N; i++) {
swap(nw, nx);
memset(dp[nx], 0, sizeof(dp[nx]));
for (int j = 0; j <= i * M; j++) {
double p = dp[nw][j] / (M-1);
dp[nx][j+1] += p;
dp[nx][j+M+1] -= p;

dp[nx][j + X[i]] -= p;
dp[nx][j + X[i] + 1] += p;
}
for (int j = 1; j <= (i + 1) * M; j++)
dp[nx][j] += dp[nx][j-1];
s += X[i];
}

double ans = 0;
for (int i = 0; i < s; i++) ans += dp[nx][i];
printf("%.10lf\n", ans + 1);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: