UESTC 1051 Eggs broken【思维+期望Dp】
2017-07-19 16:22
253 查看
Eggs broken
[b]Time Limit: 5000/2000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)[/b]Submit Status
There is a building which is nn floors high. Bob has KK same
eggs now. It is known that, the egg will be broken if Bob throws it from the nthnth floor. Now
Alice is wondering, what's the minimum expected times Bob will throw eggs until he finds the smallest xx, if Bob throws an egg from the xthxth floor
the egg will be broken.
The xx is
distributed in [1,n][1,n] uniformly.
As is known to everyone of you, Bob loves Alice very much. Could you tell Bob the answer to help Bob leave a good impression on Alice.
Input
The first line contains two integers nn and KK,which denote the number of floors and the number of eggs Bob has now.
It is guaranteed that 1≤n≤1000,1≤K≤151≤n≤1000,1≤K≤15
Output
Print the minimum expected times Bob will throw eggs in one line.The answer should be rounded to 55 digits after the decimal point.
Sample input and output
Sample Input | Sample Output |
4 2 | 2.00000 |
Source
The 13th UESTC Programming Contest Final题目大意:
现在你要在一个楼高为N的楼房上找到最低能够摔碎鸡蛋的楼数,求测试的最小步数的期望。
已知在n层的时候一定可以摔碎。
现在你拥有K个鸡蛋,鸡蛋没有碎我们可以捡起来。
思路:
设定Dp【i】【j】表示i层楼高,有j个鸡蛋的最小测试步数期望。
那么我们不难推出其状态转移方程:
①dp【n】【k】=min(dp【n】【k】,dp【i】【k-1】*(i/n)+dp【n-i】【k】*(n-i)/n+1);
②dp【1】【k】=0;
③dp【n】【1】=(1+2+3+4+..........+n-1+n-1)【如果是x==1,需要操作1步,x==2,需要操作2步..........x==n-1,需要操作n-1步,而如果x==n,我们操作n-1步即可】;
时间复杂度O(n^2K);
Ac代码:
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
double dp[1005][25];
double Cal(double a,double b)
{
return a/b;
}
void Slove(int a,int b)
{
memset(dp,0,sizeof(dp));
for(int i=1;i<=1002;i++)
{
for(int j=1;j<=22;j++)
{
dp[i][j]=100000000000000000;
}
}
for(int n=1;n<=a;n++)
{
for(int k=1;k<=b;k++)
{
if(n==1)dp
[k]=0;
else
{
if(k==1)dp
[k]=Cal((double)((n-1+((n)*(n-1))/2)),(double)(n));
else
{
for(int i=1;i<=n;i++)
{
dp
[k]=min(dp
[k],Cal((double)dp[i][k-1]*i,(double)n)+Cal((double)dp[n-i][k]*(n-i),(double)n)+(double)1);
}
}
}
}
}
printf("%.5lf\n",dp[a][b]);
}
int main()
{
int n,k;
while(~scanf("%d%d",&n,&k))
{
memset(dp,0,sizeof(dp));
Slove(n,k);
}
}
相关文章推荐
- Hdu 5236 Article【思维+期望Dp】
- UESTC 927 Dart game【思维+Dp】
- Activation HDU - 4089 概率期望dp
- ZOJ 3329 One Person Game(概率DP、求期望)
- HDU 4035 maze 概率期望dp
- Hdu 6188 Duizi and Shunzi【思维+Dp】
- HDU 4405 期望dp
- COJ1290 Random Integers 概率期望DP
- hdu 4405 Aeroplane chess (期望dp)
- ACM概率期望dp刷题总结
- BZOJ_P1076 [SCOI2008]奖励关(概率期望DP+状态压缩DP)
- BZOJ 3029 守卫者的挑战 期望DP
- lightoj 1030 lightoj 1038 基础概率dp 期望
- 数位DP 思维起步
- UESTC - 1271 Search gold (DP)
- hud 3853 LOOPS (dp求概率期望)
- 【期望DP】BZOJ2134- 单选错位
- [省选] [期望DP] [HLOI2016] 小明的智力游戏
- [BZOJ]3036 绿豆蛙的归宿 期望dp
- 1536 不一样的猜数游戏 dp思维 + 找规律