首页 > 代码库 > hdu 1203 I NEED A OFFER!

hdu 1203 I NEED A OFFER!

不懂得见blog.csdn.net/lihaogegehuting/article/details/38067455

代码如下:

#include<stdio.h>
struct node
{
   int cost;
   double wei;
} a[10004];
double min(double a,double b)
{ return  a>b? b:a;}
int main()
{
    int i,j,n,m;
    double dp[10004];
    
    while(~scanf("%d%d",&n,&m),n+m)
    {
      for(i=0;i<10004;i++)
        dp[i]=1.0;
      for(i=0;i<m;i++)
        scanf("%d%lf",&a[i].cost,&a[i].wei);
      for(i=0;i<m;i++)
        for(j=n;j>=a[i].cost;j--)
          dp[j]=min(dp[j],dp[j-a[i].cost]*(1-a[i].wei));
      printf("%.1lf%%\n",(1-dp[n])*100);
    }
    return 0;
}