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. Linux 下自解压文件的制作

    这个方法的灵感来自于 alipay 的安全控件安装,所以先感谢 alipay. 下面是经过我自己修改的自解压 shell 代码(嵌入式板子上是busybox提供的sh) #!/bin/sh # # T ...

  2. powershell小工具

    保存为.ps1文件Set-ExecutionPolicy UnrestrictedSet-ExecutionPolicy Restricted 1. 批量修改文件后缀 $CodeFileDir=&qu ...

  3. K-D Tree

    这篇随笔是对Wikipedia上k-d tree词条的摘录, 我认为解释得相当生动详细, 是一篇不可多得的好文. Overview A \(k\)-d tree (short for \(k\)-di ...

  4. PhyLab2.0需求与功能分析改进文档(NABCD)

    PhyLab1.0需求规格说明文档 1. 概述 1.1 项目概述 软剑攻城队小组于2015学年开发了PhyLab物理实验网站,一经发布好评如潮.网站的核心功能是提供预习报告和自动数据处理,而后加入了论 ...

  5. Linux 中 17 个 tar 命令实用示例

    Tar(Tape ARchive,磁带归档的缩写,LCTT 译注:最初设计用于将文件打包到磁带上,现在我们大都使用它来实现备份某个分区或者某些重要的目录)是类 Unix 系统中使用最广泛的命令,用于归 ...

  6. HTML5学习总结-01 开发环境和历史

    1 搭建HTML5开发环境 1 安装一款支持HTML5的浏览器 FireFox, Chrome 2 开发工具 SublineText, Eclipse, HBuilder, WebStorm 注:使用 ...

  7. css010 css的transform transition和animation

    css010 css的transform transition和animation 看着没有一个能想起他们是干什么的.. 1.         Transform    Transform(变形) r ...

  8. Oracle开发常用函数与存储过程

    create or replace function Fuc_Get_AuthorName(RecID_In in varchar2, AdmID_In in varchar2) return var ...

  9. WinForm------DockManager控件的使用方法(里面包含DockPanel控件)

    1.在"引用"中添加DevExpress.XtraBars和DexExpress.XtraNavBar程序集 2.往工具栏拖出DockManager控件,点击右上角的小三角,再点击 ...

  10. ioctlsocket()

    ioctlsocket()是控制套接口的模式. 外文名 ioctlsocket() 含    义 控制套接口的模式 头文件 #include <winsock.h> 性    质 函数 目 ...