• hdoj 1203 I NEED A OFFER!


    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203

    解题思路:01背包

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: hdoj 1203
     3 //user_id: SCNU20102200088
     4 ///////////////////////////////////////////////////////////////////////////
     5 
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iterator>
     9 #include <iomanip>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <string>
    13 #include <vector>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <cmath>
    17 #include <queue>
    18 #include <stack>
    19 #include <list>
    20 #include <set>
    21 #include <map>
    22 using namespace std;
    23 
    24 ///////////////////////////////////////////////////////////////////////////
    25 #pragma comment(linker,"/STACK:1024000000,1024000000")
    26 
    27 #define lson l,m,rt<<1
    28 #define rson m+1,r,rt<<1|1
    29 ///////////////////////////////////////////////////////////////////////////
    30 
    31 ///////////////////////////////////////////////////////////////////////////
    32 const double EPS=1e-8;
    33 const double PI=acos(-1.0);
    34 
    35 const int x4[]={-1,0,1,0};
    36 const int y4[]={0,1,0,-1};
    37 const int x8[]={-1,-1,0,1,1,1,0,-1};
    38 const int y8[]={0,1,1,1,0,-1,-1,-1};
    39 ///////////////////////////////////////////////////////////////////////////
    40 
    41 ///////////////////////////////////////////////////////////////////////////
    42 typedef long long LL;
    43 
    44 typedef int T;
    45 T max(T a,T b){ return a>b? a:b; }
    46 T min(T a,T b){ return a<b? a:b; }
    47 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
    48 T lcm(T a,T b){ return a/gcd(a,b)*b; }
    49 ///////////////////////////////////////////////////////////////////////////
    50 
    51 ///////////////////////////////////////////////////////////////////////////
    52 //Add Code:
    53 ///////////////////////////////////////////////////////////////////////////
    54 
    55 int main(){
    56     ///////////////////////////////////////////////////////////////////////
    57     //Add Code:
    58     int n,m,i,j,a[10005];
    59     double p[10005],dp[10005];
    60     while(scanf("%d%d",&n,&m)!=EOF){
    61         if(n==0 && m==0) break;
    62         for(i=1;i<=m;i++) scanf("%d%lf",&a[i],&p[i]);
    63         for(i=0;i<=n;i++) dp[i]=0;
    64         for(i=1;i<=m;i++){
    65             for(j=n;j>=a[i];j--){
    66                 dp[j]=max(dp[j],1-(1-dp[j-a[i]])*(1-p[i]));
    67             }
    68         }
    69         printf("%.1lf%%
    ",dp[n]*100);
    70     }
    71     ///////////////////////////////////////////////////////////////////////
    72     return 0;
    73 }
    74 
    75 ///////////////////////////////////////////////////////////////////////////
    76 /*
    77 Testcase:
    78 Input:
    79 10 3
    80 4 0.1
    81 4 0.2
    82 5 0.3
    83 0 0
    84 Output:
    85 44.0%
    86 */
    87 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    Android Studio 通过 git update 或者 pull 的时候出错及解决办法
    powershell2
    @SuppressWarnings注解用法
    IDEA设置虚拟机参数
    Java爬虫https网页内容报错SSLHandshakeException信任(忽略)所有SSL证书
    Quartz时间配置(周期任务)
    java 字符串转成 json 数组并且遍历
    linux 不能进入系统 Failed to load SELinux policy. Freezing
    linux安装mysql后报错启动不了Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
    警告:MySQL-server-5.6.26-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3320832.html
Copyright © 2020-2023  润新知