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
    在一个谎言的国度,沉默就是英雄
  • 相关阅读:
    [PA2014]Muzeum
    [TJOI2015]概率论
    To Do List
    【洛谷4172】 [WC2006]水管局长(LCT)
    HNOI2019退役记
    hdu 2159 FATE
    USACO 2019 January Contest, Platinum 题解
    luogu4774 [NOI2018]屠龙勇士
    NOI 2019游记
    loj #3145. 「APIO 2019」桥梁
  • 原文地址:https://www.cnblogs.com/EdsonLin/p/5383683.html
Copyright © 2011-2022 走看看