Codeforces Round #333 (Div. 1) C. Kleofáš and the n-thlon 树状数组优化dp
C. Kleofáš and the n-thlon
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/601/problem/C
Description
Kleofáš is participating in an n-thlon - a tournament consisting of n different competitions in n different disciplines (numbered 1 throughn). There are m participants in the n-thlon and each of them participates in all competitions.
In each of these n competitions, the participants are given ranks from 1 to m in such a way that no two participants are given the same rank - in other words, the ranks in each competition form a permutation of numbers from 1 to m. The score of a participant in a competition is equal to his/her rank in it.
The overall score of each participant is computed as the sum of that participant's scores in all competitions.
The overall rank of each participant is equal to 1 + k, where k is the number of participants with strictly smaller overall score.
The n-thlon is over now, but the results haven't been published yet. Kleofáš still remembers his ranks in each particular competition; however, he doesn't remember anything about how well the other participants did. Therefore, Kleofáš would like to know his expected overall rank.
All competitors are equally good at each discipline, so all rankings (permutations of ranks of everyone except Kleofáš) in each competition are equiprobable.
Input
The first line of the input contains two space-separated integers n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 1000) — the number of competitions and the number of participants respectively.
Then, n lines follow. The i-th of them contains one integer xi (1 ≤ xi ≤ m) — the rank of Kleofáš in the i-th competition.
Output
Output a single real number – the expected overall rank of Kleofáš. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .
Sample Input
4 10
2
1
2
1
Sample Output
1.0000000000000000
HINT
题意
有n场比赛,每场比赛有m个人参加,每场比赛都会排名次
比赛比完了,但是这个人只知道自己每场比赛的名次,并不知道其他人怎么样
于是让你求出这个人排名的期望值
题解:
期望减一后即为所有方案中得分少于主角的人数之和除去总的方案数,换个角度发现这相当于统计一个人得分少于主角的概率再乘以人数,于是dp[i][j]表示前i项比完后得分为j的概率,维护一下区间和可以优化到O(n^2*m)。
啊,我比较蠢,所以就直接用树状数组来优化了。。。
代码:
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std; int a[];
double dp[][*];
int d[][*];
struct Bit
{
double a[*];
int lowbit(int x)
{
return x&(-x);
}
double query(int x)
{
x++;
if(x<=)return ;
double ans = ;
for(;x;x-=lowbit(x))
ans+=a[x];
return ans;
}
void updata(int x,double v)
{
x++;
if(x<=)return;
for(;x<*;x+=lowbit(x))
a[x]+=v;
}
}T[];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int sum = ;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
a[]=;
if(m==)
return puts("1.00000000000000");
int now = ;
dp[now][]=;
T[now].updata(,1.0);
for(int i=;i<=n;i++)
{
now = now ^ ;
memset(dp[now],,sizeof(dp[now]));
memset(T[now].a,,sizeof(T[now].a));
for(int j=;j<=n*m;j++)
{
double K = (T[now^].query(j-) - T[now^].query(j-m-));
if(j-a[i]>=)K-=dp[now^][j-a[i]];
K*=1.0/(m-1.0);
dp[now][j] += K;
T[now].updata(j,dp[now][j]);
}
}
double res = ;
for(int i=;i<sum;i++)
res+=dp[now][i];
printf("%.15f\n",res*(m-)+1.0);
}
Codeforces Round #333 (Div. 1) C. Kleofáš and the n-thlon 树状数组优化dp的更多相关文章
- Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum (离线树状数组+前缀xor)
题目链接:http://codeforces.com/contest/703/problem/D 给你n个数,m次查询,每次查询问你l到r之间出现偶数次的数字xor和是多少. 我们可以先预处理前缀和X ...
- Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)
http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...
- Codeforces Round #365 (Div. 2)-D Mishka and Interesting sum(树状数组)
题目链接:http://codeforces.com/contest/703/problem/D 思路:看了神犇的代码写的... 偶数个相同的数异或结果为0,所以区间ans[l , r]=区间[l , ...
- Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*
D. Iahub and Xors Iahub does not like background stories, so he'll tell you exactly what this prob ...
- Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组
题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到 ...
- Codeforces Round #590 (Div. 3)【D题:26棵树状数组维护字符出现次数】
A题 题意:给你 n 个数 , 你需要改变这些数使得这 n 个数的值相等 , 并且要求改变后所有数的和需大于等于原来的所有数字的和 , 然后输出满足题意且改变后最小的数值. AC代码: #includ ...
- Codeforces 946G Almost Increasing Array (树状数组优化DP)
题目链接 Educational Codeforces Round 39 Problem G 题意 给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...
- Codeforces 909C Python Indentation:树状数组优化dp
题目链接:http://codeforces.com/contest/909/problem/C 题意: Python是没有大括号来标明语句块的,而是用严格的缩进来体现. 现在有一种简化版的Pytho ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) B. Bear and Displayed Friends 树状数组
B. Bear and Displayed Friends 题目连接: http://www.codeforces.com/contest/658/problem/B Description Lima ...
随机推荐
- Zend Framework 入门(3)—错误处理
undefined 说明脚本中一些对象没有设定 你应在在使用该对象前进行判断 例如: if(typeof(aobject) == "undefined"){ //错误处理 }
- hdu 1506(dp求最大子矩阵)
题意:容易理解... 分析:对于每个单位矩阵,我们先求出连续比它高的最左边的下标假设为l,然后求出比它高的最右边的下标假设为r,然后矩阵的面积就是(r-l+1)*1:我们从左到 右扫一遍,求出每个点的 ...
- oracle 11g在安装过程中出现监听程序未启动或数据库服务未注册到该监听程序
15511477451 原文 oracle 11g在安装过程中出现监听程序未启动或数据库服务未注册到该监听程序? 环境:win7 64位系统.oracle11g数据库 问题描述:在win7 64位系统 ...
- hdu1792 水题
最近转到vim上来了,用vim编写代码,用gcc编译,用gdb调试.这是用vim做的第一道题,纪念下.题目很水,就不说了. /* * Author : ben */ #include <cstd ...
- 【windows核心编程】线程局部存储TLS
线程局部存储TLS, Thread Local Storage TLS是C/C++运行库的一部分,而非操作系统的一部分. 分为动态TSL 和 静态TLS 一.动态TLS 应用程序通过调用一组4个函数来 ...
- rfid门禁系统笔记
非接触式IC卡性能简介 主要指标: 1:容量为8K 位的EEPROM 2:分为16个扇区,每个扇区为4块,每块16个直接,以块为存取单位 3:每个扇区有独立的一组密码和访问控制 4:每张卡具有唯一的序 ...
- <转>配置DNS辅助服务器:DNS系列之四
配置DNS辅助服务器 在前面的博文中,我们介绍了如何在DNS服务器中创建常用的DNS记录,本文中我们要为大家介绍如何配置DNS的辅助服务器,同时也要介绍一下和辅助区域类似的存根区域. DNS辅助服 ...
- 【原】Storm Local模式和生产环境中Topology运行配置
Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...
- bzoj 2595 [Wc2008]游览计划(斯坦纳树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2595 [题意] 给定N*M的长方形,选最少权值和的格子使得要求的K个点连通. [科普] ...
- windwos iis 7.5 使用html 报405错误
今天遇到了这个问题,网上搜一下基本上都是下面的答案: <form> 没有指定action的话就是文件自身了. .html本身是不可执行的,如果要修改的话,在IIS中站点属性- 主目录 - ...