zoukankan      html  css  js  c++  java
  • hdu1203 dp背包问题

    原来这就是背包呀,好吧没看题解我没写出,不过之前做过这种,就是求多项式的系数,这种模板还是很好用的,以后记住吧

    //01背包模板
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <algorithm>
    #include <string>
    #include <stack>
    #include <queue>
    
    using namespace std;
    const int inf = (1<<31)-1;
    const int MAXN = 1e4+10;
    
    struct node{
        int val;
        double p;
    }a[MAXN];
    
    double dp[MAXN];
    
    void init(){
        for(int i=0;i<MAXN;i++)
            dp[i] = 1.;
    }
    
    int main()
    {
        int n,m;
        while(scanf("%d%d",&m,&n),n||m){
            for(int i=0;i<n;i++){
                scanf("%d%lf",&a[i].val,&a[i].p);
                a[i].p = 1-a[i].p;
            }
            init();
            for(int i=0;i<n;i++){
                for(int j=m;j>=a[i].val;j--){
                    dp[j] = min(dp[j],dp[j-a[i].val]*a[i].p);
                }
            }
            printf("%.1lf%%
    ",100*(1-dp[m]));
        }
        //cout<<"debug"<<endl;
        //cout << "Hello world!" << endl;
        return 0;
    }
    //12 5 5 .5 6 .6 7 .5 2 .8 2 .7
    View Code
    在一个谎言的国度,沉默就是英雄
  • 相关阅读:
    葡萄庄园 [图论]
    硬币游戏 [博弈论, 思维题]
    烹饪 [容斥]
    BZOJ1597 [Usaco2008 Mar]土地购买 [斜率优化]
    TCP IP协议
    soap协议
    xml的语法规则
    fiddler的使用
    常见默认端口
    智能休眠时间的使用
  • 原文地址:https://www.cnblogs.com/EdsonLin/p/5383683.html
Copyright © 2011-2022 走看看