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. STM32F207和DM9161A的以太网实现方案

    摘要:电力抄表系统常通过网络采集和传输电网中的谐波等信息.本文提出了一种适合电力系统的网络设计方案.在STM32F207和DM9161A为核心的硬件平台上,完成了LwIP协议栈的移植,实现了远程终端和 ...

  2. Response 对象

    Response 对象用于将数据从服务器发送回浏览器. 页面跳转并传递参数 Response.Redirect("~/welcome.aspx?parameter1=one&para ...

  3. IOS - 打印COOKIE中的 CRFSToken

    NSHTTPCookie 在iOS中使用NSHTTPCookie类封装一条cookie,通过NSHTTPCookie的方法读取到cookie的通用属性. - (NSUInteger)version; ...

  4. Linux 中,如何显示 (gcc)make时实际执行命令

    问题: 调试编译问题,如何获取,GCC(或许make)时,实际编译器和链接器正在执行的命令? 解决方法: 方法一:通用方法 使用dry run,如下 $ make -n 这将显示make 命令正在试图 ...

  5. HTTPS 客户端验证 服务端证书流程

    网上的文章很多, 但是对摘要的验证流程不够通俗易懂. QQ截图20160420114804.png 证书预置和申请 1:客户端浏览器会预置根证书, 里面包含CA公钥2:服务器去CA申请一个证书3: C ...

  6. pulltorefresh滚动到底部

    如果用ListView,让它滚动到顶部,一般是这样写的: if (!listView.isStackFromBottom()) { listView.setStackFromBottom(true); ...

  7. Sql — CTE公用表表达式和With用法总结

    CTE(Common Table Expression) 公用表表达式,它是在单个语句的执行范围内定义的临时结果集,只在查询期间有效.它可以自引用,也可在同一查询中多次引用,实现了代码段的重复利用. ...

  8. 第五章:创建DbContext

    一.DbContext介绍 DbContext是Entity Framework(EF)操作数据库的上下文网关(接口).我们对数据库的所有操作都是通过DbContext完成的.下面我们将讨论在code ...

  9. Lucene.Net+盘古分词->开发自己的搜索引擎

    //封装类 using System;using System.Collections.Generic;using System.Linq;using System.Web;using Lucene. ...

  10. JavaScript 中 的prototype和__proto__

    1.prototype是函数的一个属性(每个函数都有一个prototype属性),这个属性是一个指针,指向一个对象.它是显示修改对象的原型的属性. 2.__proto__是一个对象拥有的内置属性(请注 ...