传送门

解题思路

  要求这个人的排名,我们可以先求出某个人比他排名靠前的概率,然后再乘上\(m-1\)即为答案。求某个人比他排名靠前可以用\(dp\),设\(f[i][j]\)表示前\(i\)场比赛某人的得分为\(j\)的概率,那么转移方程为:\(f[i][j]=\sum\limits_{k=1,k!=x[i]}^(min(m,j)) f[i-1][j-k]\),发现这个复杂度是\(O(n^2*m^2)\)的,无法接受。进一步可以看出转移形式可以前缀和优化,只需要加上前缀和后把\(k=x[i]\)这个地方挖去即可。这样时间复杂度为\(O(n^2*m)\)的,然后用滚动数组优化空间。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath> using namespace std;
const int MAXN = 105;
const int MAXM = 1005; inline int rd(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) {f=ch=='-'?0:1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
} int n,m,tot,x[MAXN];
double f[2][MAXM*MAXN],ans,sum; int main(){
n=rd(),m=rd();f[0][0]=1.0;
for(int i=1;i<=n;i++) x[i]=rd(),tot+=x[i];
for(int i=1;i<=n;i++){
sum=f[(i-1)&1][0];
for(int j=1;j<tot;j++){
f[i&1][j]=sum;
if(j>=x[i]) f[i&1][j]-=f[(i-1)&1][j-x[i]];
sum+=f[(i-1)&1][j];
if(j>=m) sum-=f[(i-1)&1][j-m];
f[i&1][j]/=(m-1);
}
if(i==1) f[0][0]=0;
}
for(int i=n;i<tot;i++)
ans+=f[n&1][i];
printf("%.15lf",ans*(m-1)+1.0);
return 0;
}

CF601C Kleofáš and the n-thlon(期望+前缀和优化dp)的更多相关文章

  1. LOJ 6089 小Y的背包计数问题 —— 前缀和优化DP

    题目:https://loj.ac/problem/6089 对于 i <= √n ,设 f[i][j] 表示前 i 种,体积为 j 的方案数,那么 f[i][j] = ∑(1 <= k ...

  2. P5241 序列(滚动数组+前缀和优化dp)

    P5241 序列 挺神仙的一题 看看除了dp好像没什么其他办法了 想着怎么构个具体的图出来,然鹅不太现实. 于是我们想办法用几个参数来表示dp数组 加了几条边肯定要的吧,于是加个参数$i$表示已加了$ ...

  3. CDOJ 1307 ABCDE 前缀和优化dp

    ABCDE 题目连接: http://acm.uestc.edu.cn/#/problem/show/1307 Description Binary-coded decimal (BCD) is a ...

  4. bzoj 1044 [HAOI2008]木棍分割——前缀和优化dp

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1044 前缀和优化. 但开成long long会T.(仔细一看不用开long long) #i ...

  5. bzoj 3398 [Usaco2009 Feb]Bullcow 牡牛和牝牛——前缀和优化dp / 排列组合

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3398 好简单呀.而且是自己想出来的. dp[ i ]表示最后一个牡牛在 i 的方案数. 当前 ...

  6. bzoj2431: [HAOI2009]逆序对数列(前缀和优化dp)

    2431: [HAOI2009]逆序对数列 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 2312  Solved: 1330[Submit][Stat ...

  7. Codeforces Round #274 (Div. 1) C. Riding in a Lift 前缀和优化dp

    C. Riding in a Lift Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/pr ...

  8. bzoj1044 [HAOI2008]木棍分割——前缀和优化DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1044 咳咳...终于A了... 居然没注意到正着找pos是n方会TLE...所以要倒着找po ...

  9. BNU 13064 Dice (I) 前缀和优化DP

    Dice (I)   You have N dices; each of them has K faces numbered from 1 to K. Now you have arranged th ...

随机推荐

  1. Allowance

    Allowance 有n种数字,第i种数字值为\(v_i\),有\(b_i\)个,保证随i的增大而增大,且对于任意i有\(a_{i-1}|a_i\)(显然,\(i\in(1,n]\)),现求将它们划分 ...

  2. Dubbo---zookeeper 注册中心---xml配置

    1.项目结构(maven项目) 2.pom <?xml version="1.0" encoding="UTF-8"?> <project x ...

  3. PyCharm Change Font Size

    file->settings->colors&fonts-> save as (save the current scheme as your own)-> font- ...

  4. mongodb客户端操作常用命令(续)

    之前有写过一篇mongodb客户端的操作常用命令 ,今天接着来记录分享一些关于mongodb账户权限设置的命令操作 上期mongodb客户端的操作常用命令地址:https://www.cnblogs. ...

  5. Ubuntu开放对外端口

    1.查看已经开启的端口 sudo ufw status 2.打开80端口 sudo ufw allow 80 3.防火墙开启 sudo ufw enable 4.防火墙重启 sudo ufw relo ...

  6. CacheException: java.io.OptionalDataException

    CacheException: java.io.OptionalDataException iro.authc.AbstractAuthenticator] - Authentication fail ...

  7. WPF ListBox 横向排列

    WPF ListBox 横向排列   如果只是单纯的让ListBox可以横向配列,这样很简单,只需要更改ListBox的ItemsPanel模板就可以,例如: <ListBox><L ...

  8. SELinux导致PHP连接MySQL异常Can't connect to MySQL server的解决方法

    原文摘自:http://www.jb51.net/article/52581.htm 这篇文章主要介绍了SELinux导致PHP连接MySQL异常Can't connect to MySQL serv ...

  9. Ext 选项卡面板TabPanel

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 在Windows的控制台和Linux的终端中显示加载进度

    Windows中 #include <stdio.h> #include <windows.h> int main() { ;//任务完成总量 int i; ; i < ...