HDU 1203 I NEED A OFFER!

0-1背包

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;



const int maxn=10000+10;

const int INF=0x7FFFFFFF;

int n,m;

int a[maxn];

double b[maxn];

double DP[maxn];



int main()

{

    int i,j;

    while(~scanf("%d%d",&n,&m))

    {

        if(n==0&&m==0) break;

        for(i=1; i<=m; i++)

        {

            scanf("%d%lf",&a[i],&b[i]);

            b[i]=1-b[i];

        }

        for(i=0; i<=n; i++) DP[i]=1;

        for(i=1; i<=m; i++)

            for(j=n; j-a[i]>=0; j--)

                DP[j]=fmin(DP[j],DP[j-a[i]]*b[i]);

        double MIN=INF;

        for(i=0; i<=n; i++)

            if(MIN>DP[i])

                MIN=DP[i];

        MIN=MIN*100;

        printf("%.1lf",100-MIN);

        printf("%%\n");

    }

    return 0;

}

 

你可能感兴趣的:(HDU)