HDU 1203(01背包)

来源:互联网 发布:vhf天线仿真软件 编辑:程序博客网 时间:2024/05/11 04:32

题意:如题。

 

#include <cstring>#include <cstdio>#define maxn 1009#define _min(a, b) ((a) < (b) ? (a) : (b))int cost[maxn];double weight[maxn];double dp[10009];int main(){    int n, m, i;    while (scanf("%d%d", &n, &m) != EOF && (n || m))    {        for (i = 0; i < m; ++i)            scanf("%d%lf", cost+i, weight+i), weight[i] = 1 - weight[i];        for (i = 0; i <= n; ++i) dp[i] = 1.0;        int last = 0;        for (i = 0; i < m; ++i)            for (int j = _min(n, last+=cost[i]); j >= cost[i]; --j)                dp[j] = _min(dp[j], dp[j-cost[i]] * weight[i]);        printf("%.1lf%%\n", (1 - dp[n]) * 100);    }    return 0;}


 

0 0