ZOJ 3640

很简单的概率题了

设dp[x]为能力值 为x时出去的期望 天数

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
double dp[20005];
int ci[125];
double is=0.5*(1+sqrt(5));
int main(){
	int n,f,ma;
	while(scanf("%d%d",&n,&f)!=EOF){
		ma=-1;
		for(int i=1;i<=n;i++){
			scanf("%d",&ci[i]);
			ma=max(ma,ci[i]);
		}
		ma=ma*2;
		for(int i=max(ma,f);i>=f;i--){
			dp[i]=0;
			for(int k=1;k<=n;k++){
				if(i>ci[k]) dp[i]+=(int)(is*ci[k]*ci[k]);
				else{
					dp[i]+=(dp[i+ci[k]]+1);
				}
			}
			dp[i]=(dp[i])/n;
		}
		printf("%.3lf
",dp[f]);
	}
	return 0;
}

  

原文地址:https://www.cnblogs.com/jie-dcai/p/4109123.html