hdu 1203 I NEED A OFFER!--01背包

/*
	01背包问题
*/
#include<stdio.h>
double dp[10010],g[1010];
int m[1010],qian;
double p(double w,int i)
{
	return 1-(1-w)*(1-dp[i]);
}
void zopack(int c,double w)
{
	int i;
	double gg;
	for(i=qian;i>=c;i--)
	{
		gg=p(w,i-c);
		dp[i]=gg>dp[i]?gg:dp[i];
	}
}
int main()
{
	int n,i;
	while(scanf("%d%d",&qian,&n),n+qian)
	{
		for(i=0;i<n;i++)
			scanf("%d%lf",&m[i],&g[i]);
		for(i=0;i<=qian;i++)
			dp[i]=0;
		for(i=0;i<n;i++)
			zopack(m[i],g[i]);
		printf("%.1f%%\n",dp[qian]*100);
	}
	return 0;
}

你可能感兴趣的:(hdu 1203 I NEED A OFFER!--01背包)