http://acm.hdu.edu.cn/showproblem.php?pid=1203

01背包
ps:做01背包经常不注意数组的大小,这题数组开小了又是各种wa
View Code
#include <iostream>
using namespace std ;
double f[10001],w[1001];
int c[1001];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m))
    {
        if(n==0&&m==0)break;
        for(int i=1;i<=m;i++)
            scanf("%d%lf",&c[i],&w[i]);
        memset(f,0.0,sizeof(f));
        for(int i=1;i<=m;i++)
            for(int v=n;v>=c[i];v--)
                f[v]=max(f[v],1-(1-f[v-c[i]])*(1-w[i]));
        printf("%.1lf%%\n",f[n]*100);
    }
    return 0;
}