这道题的数据超级神,,,有木有!有木有!!!!!!!变态的数据,明明是一道简单题,却非要让大家wr了5、6次,无语。。。。。就是个0-1背包。题目让求得到offer的最大概率,只需要求出得不到offer的最小概率即可。题目:
10 3 4 0.1 4 0.2 5 0.3 0 0
44.0%HintYou should use printf("%%") to print a '%'.
#include <iostream> #include <cstdio> #include <string.h> using namespace std; struct school{ int fee; double possible; }aa[1005]; double min(double a,double b){ return a<b?a:b; } int main(){ //freopen("4.txt","r",stdin); int n,m; while(scanf("%d%d",&n,&m)){ if(n==0&&m==0) break; if(m==0) {printf("0.0%%\n");continue;} double pos,dp[10005]; for(int i=1;i<=m;++i){ scanf("%d%lf",&aa[i].fee,&pos); aa[i].possible=1.0-pos; } for(int i=0;i<=n;++i) dp[i]=1.0; for(int i=1;i<=m;++i){ for(int v=n;v>=aa[i].fee;--v){ dp[v]=min(dp[v],dp[v-aa[i].fee]*aa[i].possible); } } double xx=1.0; for(int i=0;i<=n;++i) if(xx>dp[i]) xx=dp[i]; double pp=(1.0-xx)*100.0; printf("%.1lf%%\n",pp); } return 0; }