zoukankan      html  css  js  c++  java
  • hdu1203

    这个题是0,1背包

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    using namespace std;
    const int maxn = 1e4+10;
    double dp[maxn];
    int w[maxn];
    double v[maxn];
    int main()
    {
        int n,m,i,j;
        while(scanf("%d%d",&n,&m) && n+m)
        {
            memset(dp, 0, sizeof(dp));
            for(i=0; i < m; ++i)
            {
                scanf("%d %lf",w+i,v+i);
                v[i] = 1.0-v[i];
            }
            for(j=0; j <= n; ++j)
            {
                dp[j] = 1.0;
            }
            for(i=0; i<m; ++i)
            {
                for(j=n ; j>=w[i]; --j)
                {
                    dp[j] = min(dp[j],dp[j-w[i]]*v[i]);
                }
            }
            printf("%.1f%%
    ",(1.0-dp[n])*100);
        }
    }
  • 相关阅读:
    第八章
    第十章
    第九章
    第七章
    第六章
    第五章
    第四章心得
    第二章心得
    第三章心得
    第一章心得
  • 原文地址:https://www.cnblogs.com/mltang/p/8725326.html
Copyright © 2011-2022 走看看