hdu_3366 Passage

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m;
double dp[1010][20],ans;
struct edge{double p,q;}a[1010];

bool cmp(edge x,edge y){return x.p/x.q>y.p/y.q;}

int main(){
	int T;
	scanf("%d",&T);
	for(int t=1;t<=T;t++){
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)scanf("%lf%lf",&a[i].p,&a[i].q);
		ans=0;
		memset(dp,0,sizeof(dp));
		sort(a+1,a+n+1,cmp);
		dp[1][m]=1.0;
		for(int i=1;i<=n;i++)
			for(int j=m;j>=0;j--){
				dp[i+1][j-1]+=dp[i][j]*a[i].q;
				dp[i+1][j]+=dp[i][j]*(1.0-a[i].p-a[i].q);
				ans+=dp[i][j]*a[i].p;
			}
		printf("Case %d: %.5lf\n",t,ans);
	}
	return 0;
}

  

posted @ 2020-08-06 20:41  wqtnb_tql_qwq_%%%  阅读(78)  评论(0编辑  收藏  举报