概率dp ZOJ 3640

Help Me Escape

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld
& %llu

Submit Status Practice ZOJ
3640

Appoint description: 
System Crawler  (2014-10-22)

Description

Background

    If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him.

And Cain talked with Abel his brother: and it came to pass, when they were in the field, that Cain rose up against Abel his brother, and slew him.

And the LORD said unto Cain, Where is Abel thy brother? And he said, I know not: Am I my brother‘s keeper?

And he said, What hast thou done? the voice of thy brother‘s blood crieth unto me from the ground.

And now art thou cursed from the earth, which hath opened her mouth to receive thy brother‘s blood from thy hand;

When thou tillest the ground, it shall not henceforth yield unto thee her strength; a fugitive and a vagabond shalt thou be in the earth.

—— Bible Chapter 4

Now Cain is unexpectedly trapped in a cave with N paths. Due to LORD‘s punishment, all the paths are zigzag and dangerous. The difficulty of the ith path is ci.

Then we define f as the fighting capacity of Cain. Every day, Cain will be sent to one of the N paths randomly.

Suppose Cain is in front of the ith path. He can successfully take ti days to escape from the cave as long as his fighting capacity f is larger than ci. Otherwise, he has to keep trying day after day. However,
if Cain failed to escape, his fighting capacity would increase cias the result of actual combat. (A kindly reminder: Cain will never died.)

As for ti, we can easily draw a conclusion that ti is closely related to ci. Let‘s use the following function to describe their relationship:

After D days, Cain finally escapes from the cave. Please output the expectation of D.

Input

The input consists of several cases. In each case, two positive integers N and f (n ≤ 100, f ≤ 10000) are given in the first line. The second line includes N positive integers ci (ci ≤ 10000,
1 ≤ i ≤ N)

Output

For each case, you should output the expectation(3 digits after the decimal point).

Sample Input

3 1
1 2 3

Sample Output

6.889
/*************************************************************************
    > File Name: t.cpp
    > Author: acvcla
    > Mail: [email protected]
    > Created Time: 2014年10月21日 星期二 21时33分55秒
 ************************************************************************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<cstdlib>
#include<ctime>
#include<set>
#include<math.h>
using namespace std;
typedef long long LL;
const int maxn = 20000 + 10;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
int n,c[105],f;
double dp[maxn];
double d(int f){
	if(dp[f]>0)return dp[f];
	dp[f]=0;
	for(int i=1;i<=n;i++){
		if(f>c[i]){
			int t=(1+sqrt(5))*c[i]*c[i]/2;
			dp[f]+=(double)t/n;
		}else{
			dp[f]+=(1+d(f+c[i]))/n;
		}
	}
	return dp[f];
}
int main(int argc, char const *argv[])
{
	while(~scanf("%d%d",&n,&f)){
		memset(dp,0,sizeof dp);
		for(int i=1;i<=n;i++)scanf("%d",c+i);
		printf("%.3f\n",d(f));
	}
	return 0;
}
时间: 2024-10-03 13:38:45

概率dp ZOJ 3640的相关文章

[概率dp] zoj 3822 Domination

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3822 Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays che

zoj 3640 概率dp

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4808 Background     If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him. And Cai

ZOJ 3551 Bloodsucker (概率DP)

ZOJ Problem Set - 3551 Bloodsucker Time Limit: 2 Seconds      Memory Limit: 65536 KB In 0th day, there are n-1 people and 1 bloodsucker. Every day, two and only two of them meet. Nothing will happen if they are of the same species, that is, a people

【概率DP】 ZOJ 3380 Patchouli&#39;s Spell Cards

通道 题意:有m个位置,每个位置填入一个数,数的范围是1~n,问至少有L个位置的数一样的概率 思路: 总数是n^m,我们求没有L个位置一样的数的概率 * 设 dp[i][j]表示用前i个数,填充j个位置的方案数(要符合没有L个位置是一样的数) * dp[i][j]=dp[i-1][j]+Sigm( dp[i-1][j-k]*C[m-(j-k)][k] ) k<=j&&k<L * 其实就是看第i个数,可以不填,填一个位置,两个位置······这样累加过来. * 那么最后的答案就是

[ACM] ZOJ 3329 One Person Game (概率DP,有环,巧妙转化)

One Person Game Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge There is a very simple and interesting one-person game. You have 3 dice, namely Die1, Die2 and Die3. Die1 has K1 faces. Die2 has K2 faces. Die3 has K3 faces. All the

Zoj 3380 Patchouli&#39;s Spell Cards (概率dp)

题目大意: 用(1 2 3 ... n) n个数填充 m个位置,问最少相同的数字出现的数量不少于I 的概率 思路分析: 逆向思考,求铺满最多的数量不够I 个的方案数. 每次用一个数字去铺,铺M个位置,每个数字最多铺 不够I个. dp[i][j]表示枚举到了第i个数字,前i个数字铺了j个位置的方案数. 考虑到组合计数 用Java import java.util.*; import java.io.BufferedInputStream; import java.math.*; public cl

zoj 3299 概率dp

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3329 回头重推式子 题解:http://blog.csdn.net/morgan_xww/article/details/6775853#reply 学到: 1.目前做的两道期望的状态转移方程都是从大向小推,定义方式:dp[i][j][k]....  满足i,j,k时,要达到upbound(i),upbound(j),upbound(k),需要XX的期望 2.待定系数的方

zoj 3822 Domination 【概率DP 求期望】

Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays chess with his friends. What's more, he bought a large decorative chessboar

zoj 3288 Domination (概率dp)

///dp[i][j][k]表示i行j列已经有棋子,且放了k个的概率 ///dp[i][j][k]一共有四种转移方式 ///1:dp[i-1][j][k-1] 概率为 (n-(i-1))*j/(n*m-(k-1)) ///2:dp[i][j-1][k-1] 概率为 i*(m-(j-1))/(n*m-(k-1)) ///3:dp[i-1][j-1][k-1] 概率为 (n-(i-1))*(m-(j-1))/(n*m-(k-1)) ///4:dp[i][j][k-1] 概率为 (i*j-(k-1))