Give Me Your Hand


Time Limit: 2 Seconds      Memory Limit: 131072 KB      Special Judge

BellyWhite and MightyHorse are two students of Marjar University. They are best friends and also roommates living in the same dorm. There are K students living in that dorm, including BellyWhite and MightyHorse.

BellyWhite posted a strange microblog in 2012-9-3:

This is quite strange. It means that BellyWhite will chop some "hands" into pieces if he's been found playing games or some other activities which is not relevant to his research. This logic is insane, isn't it?

We could call those things which are not relevant to BellyWhite's research "bad things". Now we know that BellyWhite will start doing bad things when he's in the dorm for T minutes, and he will stop doing those things when he's being warned by MightyHorse or leaving the dorm. If he's been warned to stop doing bad things and then he stays in the dorm for another T minutes, he will start doing bad things again.

MightyHorse noticed the strange microblog BellyWhite posted, but he's a good roommate, so he must took the risk of losing his "hands" to warn BellyWhite that he was doing something harmful to his research progress or even his PhD degree. Fortunately, MightyHorse has M plastic toy "hands", so BellyWhite will only chop those toy hands into pieces when he's being warned.

Here comes the problem. We only know that no one is in the dorm initially, and we heard N door open and close sounds, which means there are N people entered or exited the dorm. We logged exact time of all door sounds, but we don't know who made the sound, that means all K students living in the dorm have the same possibility to enter / exit. We'd like to know the expected number of toy hands MightyHorse will have after 24 hours (1440 minutes).

Please note that using toy hand to stop BellyWhite from doing bad things take no time, which means that even at the moment MightyHorse or BellyWhite enter / exit the dorm, a toy hand will be used to stop the bad thing. But if that there's no toy hand left, MightyHorse will not able to stop BellyWhite from doing bad things.

Input

There are multiple test cases. The first line of input is an integer Casenum indicating the number of test cases.

For each test case, the first line contains 4 integers T (1 ≤ T ≤ 100), N (1 ≤ N ≤ 100), M (1 ≤ M ≤ 100) and K (2 ≤ K ≤ 8) which are defined in descriptions above.

The following line contains N integers. For every integer ti(0 ≤ ti ≤ 1440, 0 ≤ i < N), it means that a student entered or exited the dorm at time ti.

We guarantee that all those N ti will be given in strictly increasing order.

Output

For each test case, output the expected number of toy hands that MightyHorse still have at time 1440, rounded to 6 decimal points.

Sample Input

260 2 10 2200 260100 2 8 51340 1341

Sample Output

5.0000007.960000


Author: FAN, Yuzhe
Contest: The 10th Zhejiang Provincial Collegiate Programming Contest

 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; double dp[][][][];
///dp[第几次][位置关系][被警告一次后再屋内待了多久][剩下几只手]=概率
int t[]; int ca,T,N,M,K; int main()
{
scanf("%d",&ca);
while(ca--)
{
scanf("%d%d%d%d",&T,&N,&M,&K);
memset(dp,,sizeof(dp));
dp[][][][M]=1.0;t[]=;
for(int i=;i<=N;i++)
{
scanf("%d",&t[i]);
int ti=t[i]-t[i-];
///state 0: b X m X
for(int j=;j<=M;j++)
{
dp[i][][][j]+=dp[i-][][][j]*(K-.)*./K;
dp[i][][][j]+=dp[i-][][][j]*./K;
dp[i][][][j]+=dp[i-][][][j]*./K;
}
///state 1: b X m Y
for(int j=;j<=M;j++)
{
dp[i][][][j]+=dp[i-][][][j]*./K;
dp[i][][][j]+=dp[i-][][][j]*(K-.)*./K;
dp[i][][][j]+=dp[i-][][][j]*./K;
}
///state 2 b Y m X
for(int k=;k<=T;k++)
{
for(int j=;j<=M;j++)
{
dp[i][][][j]+=dp[i-][][k][j]*./K;
dp[i][][min(T,k+ti)][j]+=dp[i-][][k][j]*(K-.)*./K;
dp[i][][(k+ti)>=T?:(k+ti)][max(,j-((k+ti)>=T))]+=dp[i-][][k][j]*./K;
}
}
///state 3 b Y m Y
for(int k=;k<=T;k++)
{
for(int j=;j<=M;j++)
{
dp[i][][][max(,j-(k+ti)/T)]+=dp[i-][][k][j]*./K;
dp[i][][(k+ti)%T][max(,j-(k+ti)/T)]+=dp[i-][][k][j]*./K;
dp[i][][(k+ti)%T][max(,j-(k+ti)/T)]+=dp[i-][][k][j]*(K-.)/K;
}
}
}
double ans=.;
for(int i=;i<=T;i++)
{
for(int j=;j<=;j++)
{
for(int k=;k<=M;k++)
{
ans+=dp[N][j][i][k]*k;
}
}
}
int ti=-t[N];
for(int i=;i<=T;i++)
{
for(int j=;j<=M;j++)
{
ans+=dp[N][][i][j]*max(,j-(i+ti)/T);
}
}
printf("%.6lf\n",ans);
}
return ;
}

ZOJ 3711 Give Me Your Hand的更多相关文章

  1. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  2. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  3. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  4. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  5. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  6. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  7. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

  8. zoj 1788 Quad Trees

    zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...

  9. ZOJ 1958. Friends

    题目链接: ZOJ 1958. Friends 题目简介: (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合. (2)用运算 ...

随机推荐

  1. 验证时出错。HRESULT = '8000000A'

    往往出现在 做了安装项目后有警告: 解决办法: 这本来是在VS2005下创建的一下项目,后来改用VS2010的开发环境,.NET Framework的版本还是使用2.0, 但每次生成之后都会在解决方案 ...

  2. WebConfig节点详解

    <!-- Web.config配置文件详解(新手必看) 花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法. 很适合新手参看,由于Web.config在使用很灵活,可 ...

  3. MOOCULUS微积分-2: 数列与级数学习笔记 1. Sequences

    此课程(MOOCULUS-2 "Sequences and Series")由Ohio State University于2014年在Coursera平台讲授. PDF格式教材下载 ...

  4. POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)

    传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...

  5. libjpeg 编译makfile

    一.准备 首先需要下载libjpeg库,网址在这里:http://www.ijg.org/ 如果不想编译就在这下载吧:http://pan.baidu.com/s/1hqeTDre 二.编译 1. 解 ...

  6. window.location.href的用法

    在写ASP.Net程序的时候,我们经常遇到跳转页面的问题,我们经常使用Response.Redirect 做ASP.NET框架页跳转,如果客户要在跳转的时候使用提示,这个就不灵光了,如: Respon ...

  7. C#------如何判断输入的是否为纯数字

    private void Btn_OK_Click(object sender, EventArgs e) { IDormitoryAdminCardService aservice = new Do ...

  8. coreseek 中文搜索和高亮

    配置文件 # # Minimal Sphinx configuration sample (clean, simple, functional) # source post { type = mysq ...

  9. 基于centOS6.7搭建LAMP(httpd-2.4.18+mysql-5.5.47+php-5.6.16)环境

    首先确保系统可以联网.设置IP地址以及虚拟机安装linux在此略过.本文采用centos6.7 64位minimal版.php5.6.16.httpd-2.4.18.mysql-5.5.47版搭建la ...

  10. springmvc @responseBody自动打包json出现错误(外键查询死循环)问题

    在外键字段的get方法上加入@JsonIgnore