HDU 1203 I NEED A OFFER!【01背包】
大意:01背包
分析:01背包
代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn = 10005; 7 const int INF = 1000000000; 8 9 double dp[maxn]; 10 int cost[maxn]; 11 double prob[maxn]; 12 int main() { 13 int n, m; 14 while(scanf("%d %d",&n, &m) && ( n + m ) ) { 15 for(int i = 1; i <= m; i++) { 16 scanf("%d %lf",&cost[i], &prob[i]); 17 } 18 for(int i = 0; i <= n; i++) dp[i] = 1.0; 19 for(int i = 1; i <= m; i++) { 20 for(int j = n; j >= cost[i]; j--) { 21 dp[j] = min(dp[j], dp[j - cost[i]] * (1.0 - prob[i])); 22 } 23 } 24 double ans = 1.0 - dp[n]; 25 ans *= 100; 26 printf("%.1lf%%\n",ans); 27 } 28 return 0; 29 }