01背包:P(至少一个offer) = 1 - P(拥有全部offer)
#include<stdio.h> #include<cstdio> #include<iostream> #include<algorithm> #include<math.h> #include<stdlib.h> #include<string.h> #include<string> #include<queue> #include<map> #define LL long long #define INF 0xfffffff #define MAX(a,b) a>b?a:b #define MIN(a,b) a<b?a:b using namespace std; double v[1000005],dp[1000005]; int w[1000005]; int main() { int n,m; while(scanf("%d%d",&n,&m),n+m) { for(int i=1;i<=m;i++) { scanf("%d%lf",&w[i],&v[i]); v[i] = 1-v[i]; } for(int i=0;i<=n;i++) dp[i] = 1; for(int i=1;i<=m;i++) { for(int j=n;j>=w[i];j--) { dp[j] = min(dp[j],dp[j-w[i]]*v[i]); } } double ans = (1 - dp[n])*100; printf("%.1f%% ",ans); } return 0; }