HDU 1203 ( I NEED A OFFER! )
程序员文章站
2022-06-07 14:44:43
...
我做的第一个背包问题
Problem : 1203 ( I NEED A OFFER! ) Judge Status : Accepted RunId : 6357811 Language : C++ Author : ssun Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta #include "iostream" #include "stdio.h" using namespace std; double min(double a, double b){ return a < b ? a : b; } int main(){ double possible[11000],ans[11000]; int n,m,i,k,cost[11000]; while(cin>>m>>n,m || n){ for(i=0; i<n; i++){ cin>>cost[i]>>possible[i]; } for(i=0; i<=m; i++) ans[i] = 1; for(i=0; i<n; i++){ for(k=m; k>=cost[i]; k--){ ans[k] = min(ans[k], ans[k-cost[i]]*(1-possible[i])); } } printf("%.1lf%%\n",(1-ans[m])*100); } return 0; }