zoukankan      html  css  js  c++  java
  • I NEED A OFFER! hdu1203(背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=1203

    分析:题中有两个字“至少”,所以我们可以选择算一个也不可能的概率为多少,再用1减去它,即可获得所要答案。

    #include<stdio.h>
    #include<math.h>
    #include<string.h>
    #include<ctype.h>
    #include<stdlib.h>
    #include <iostream>
    #include<algorithm>
    #include<queue>
    #define maxn 11000
    #define oo 0x3f3f3f3f
    using namespace std;
    int a[maxn];
    double b[maxn],dp[maxn];
    
    int main()
    {
        int n, m;
    
        while(scanf("%d %d", &n, &m),n+m)
        {
            for(int i=1; i<=m; i++)
            {
                 scanf("%d %lf", &a[i], &b[i]);
                 b[i] = 1-b[i];
            }
    
    
            for(int i=0; i<=n; i++)
               dp[i] = 1;
    
           for(int i=1; i<=m; i++)
           {
               for(int j=n; j>=a[i]; j--)
               {
                   dp[j]=min(dp[j], dp[j-a[i]]*b[i]);
               }
           }
    
    
          printf("%.1f%%
    ", (1-dp[n])*100);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    zbb20180930 Postman 使用方法详解
    Cookie、Session、jsp、EL、JSTL
    Http协议、Tomcat、servlet
    xml、网络编程、 反射
    JDBC、DBUtils
    Java IO流对象、多线程
    mySql
    Java基础
    VueJs
    GIT
  • 原文地址:https://www.cnblogs.com/daydayupacm/p/5735878.html
Copyright © 2011-2022 走看看