ZOJ 3711 Give Me Your Hand

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 


 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 
 5 using namespace std;
 6 
 7 double dp[110][4][110][110];
 8 ///dp[第几次][位置关系][被警告一次后再屋内待了多久][剩下几只手]=概率
 9 int t[110];
10 
11 int ca,T,N,M,K;
12 
13 int main()
14 {
15     scanf("%d",&ca);
16     while(ca--)
17     {
18         scanf("%d%d%d%d",&T,&N,&M,&K);
19         memset(dp,0,sizeof(dp));
20         dp[0][0][0][M]=1.0;t[0]=0;
21         for(int i=1;i<=N;i++)
22         {
23             scanf("%d",&t[i]);
24             int ti=t[i]-t[i-1];
25             ///state 0: b  X   m  X
26             for(int j=0;j<=M;j++)
27             {
28                 dp[i][0][0][j]+=dp[i-1][0][0][j]*(K-2.)*1./K;
29                 dp[i][1][0][j]+=dp[i-1][0][0][j]*1./K;
30                 dp[i][2][0][j]+=dp[i-1][0][0][j]*1./K;
31             }
32             ///state 1: b X m Y
33             for(int j=0;j<=M;j++)
34             {
35                 dp[i][0][0][j]+=dp[i-1][1][0][j]*1./K;
36                 dp[i][1][0][j]+=dp[i-1][1][0][j]*(K-2.)*1./K;
37                 dp[i][3][0][j]+=dp[i-1][1][0][j]*1./K;
38             }
39             ///state 2 b Y  m X
40             for(int k=0;k<=T;k++)
41             {
42                 for(int j=0;j<=M;j++)
43                 {
44                     dp[i][0][0][j]+=dp[i-1][2][k][j]*1./K;
45                     dp[i][2][min(T,k+ti)][j]+=dp[i-1][2][k][j]*(K-2.)*1./K;
46                     dp[i][3][(k+ti)>=T?0:(k+ti)][max(0,j-((k+ti)>=T))]+=dp[i-1][2][k][j]*1./K;
47                 }
48             }
49             ///state 3 b Y m Y
50             for(int k=0;k<=T;k++)
51             {
52                 for(int j=0;j<=M;j++)
53                 {
54                     dp[i][1][0][max(0,j-(k+ti)/T)]+=dp[i-1][3][k][j]*1./K;
55                     dp[i][2][(k+ti)%T][max(0,j-(k+ti)/T)]+=dp[i-1][3][k][j]*1./K;
56                     dp[i][3][(k+ti)%T][max(0,j-(k+ti)/T)]+=dp[i-1][3][k][j]*(K-2.)/K;
57                 }
58             }
59         }
60         double ans=0.;
61         for(int i=0;i<=T;i++)
62         {
63             for(int j=0;j<=2;j++)
64             {
65                 for(int k=0;k<=M;k++)
66                 {
67                     ans+=dp[N][j][i][k]*k;
68                 }
69             }
70         }
71         int ti=1440-t[N];
72         for(int i=0;i<=T;i++)
73         {
74             for(int j=0;j<=M;j++)
75             {
76                 ans+=dp[N][3][i][j]*max(0,j-(i+ti)/T);
77             }
78         }
79         printf("%.6lf\n",ans);
80     }
81     return 0;
82 }

 

 

Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值