//I NEED A OFFER! //0/1背包 #include<stdio.h> #include<string.h> float min(float a,float b); int main(){ int m,n,i,j,a[10005]; float b[10005],dp[10005]; while(scanf("%d%d",&m,&n)!=EOF&&(m||n)){ for(i=0;i<n;i++) scanf("%d%f",&a[i],&b[i]);//float %f for(i=0;i<10005;i++) dp[i]=1; //memset(dp,1.0,sizeof(dp)); for(i=0;i<n;i++){ for(j=m;j>=0;j--){ if(j>=a[i]) dp[j]=min(dp[j],dp[j-a[i]]*(1-b[i]));//转态方程 } } printf("%0.1f%%\n",(1-dp[m])*100); } return 0; } float min(float a,float b){ return(a<b?a:b); }
时间: 2024-11-09 17:17:57