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 ...
随机推荐
- Android01--开发环境搭建
1 -- 下载所需软件 Android SDK下载地址:http://developer.android.com/sdk/index.html Eclipse下载地址:http://www.eclip ...
- VS2013密匙
在网上找到的,亲测有用: BWG7X-J98B3-W34RT-33B3R-JVYW9
- android学习—— context 和 getApplicationContext()
一直看到好多应用里面,随手使用getApplicationContext(),不想说也不乐意说,今天转载一篇文章区分两者的区别: 在android中常常会遇到与context有关的内容 浅论一下con ...
- http://jingyan.baidu.com/article/4dc40848e7b69bc8d946f127.html
http://jingyan.baidu.com/article/4dc40848e7b69bc8d946f127.html
- webdriver(python) 学习笔记三
知识点:简单的对象定位 对象的定位应该是自动化测试的核心,要想操作一个对象,首先应该识别这个对象.一个对象就是一个人一样,他会有各种的特征(属性),如比我们可以通过一个人的身份证号,姓名,或者他住在哪 ...
- 四款超棒的jQuery数字化签名插件
在浏览器中,我们有很多方式来绘制生成签名效果,并且有很多很棒很智能的jQuery插件.数字化签名是未来的发展方向,正是这个原因我们这里收集并且推荐了四款超棒的jQuery数字化签名插件,希望大家喜欢! ...
- (三)相遇射线的3D碰撞盒
序 在2D游戏中,我们知道处理碰撞时,需要设置精灵遮罩图.同样,进入3D,处理碰撞时需要3D模型作为“遮罩图”. 索尼克 飞檐走壁 目的 (1)处理模型间的碰撞问题 (2)获取鼠标 ...
- Kindle Paperwhite 2使用体验
博客开通后一懒就扔下了几十天,着实自惭.鉴于是第一篇,先说点题外话. 一转眼读研的生活已经过去一年有余.曾经的同学已经在职场拼搏,同龄人的生活状态也自然地带给自己一份紧迫感:不敢再贪恋校园生活的安逸, ...
- Todolist
UValive 6041(KD tree) UValive 6042(DP) UValive 6044(图论)
- Bone.io是一个轻量级的框架构建高性能实时单页HTML5应用程序
Bone.io允许你使用HTML5 WebSockets构建实时应用程序,提供“热”数据到浏览器.这使您可以轻松地构建丰富的,高度响应的用户界面. 项目主页:http://www.open-open. ...