原来这叫背包..
1 #include <cstdio> 2 #include <algorithm> 3 4 // dp[i] is the possibility he can get at least 1 offer when i yuan have been taken. 5 int n, m, a[10010]; 6 double dp[10010], b[10010]; 7 8 int main(int argc, char const *argv[]) 9 { 10 // freopen("_in", "r", stdin); 11 while(scanf("%d%d", &n, &m)){ 12 if(n==0 && m==0) 13 break; 14 for(int i = 1; i <= m; ++i) 15 scanf("%d %lf", a+i, b+i); 16 17 for(int i = 0; i <= n; ++i) 18 dp[i] = 1.0; 19 20 for(int i = 1; i <= m; ++i) 21 for(int j = n; j >= a[i]; --j) 22 dp[j] = std::min(dp[j], dp[ j-a[i] ]*(1-b[i]) ); 23 24 25 26 printf("%.1lf%%\n", (1-dp[n])*100 ); 27 } 28 return 0; 29 }
时间: 2024-10-13 15:12:55