hdu I NEED A OFFER!

本文介绍了如何通过转换问题视角,将0/1背包问题中的最大概率转换为不能录取的最小概率,从而简化解题过程。详细阐述了状态方程的应用,并提供了C++代码实现,帮助读者理解并解决类似问题。

这道题是道很基本的0/1背包的问题,为了使解题很简单一点,可以将题目中要求的最大概率转换成不能录取的最小概率,这样1-dp[n]即为至少有一个offer的最大概率。状态方程

为:dp[j]=min{dp[j],dp[j-price[i]]*chance[i]};

 1 #include"iostream"
 2 #include"stdio.h"
 3 #include"algorithm"
 4 #include"string.h"
 5 #include"cmath"
 6 #include"queue"
 7 #define mx 10005
 8 using namespace std;
 9 int price[mx];
10 double chance[mx];
11 double dp[mx];
12 int main()
13 {
14     int n,m,i,j,k;
15     while(cin>>n>>m,n||m)
16     {
17         for(i=1;i<=m;i++)
18         {
19             cin>>price[i]>>chance[i];
20             chance[i]=1-chance[i];
21         }
22         for(i=0;i<=n;i++) dp[i]=1;
23         for(i=1;i<=m;i++)
24         {
25             for(j=n;j>=price[i];j--)
26             {
27                 if(dp[j]>dp[j-price[i]]*chance[i])dp[j]=dp[j-price[i]]*chance[i];
28             }
29         }
30         printf("%.1lf%%\n",(1-dp[n])*100);
31     }
32     return 0;
33 }
View Code

 

转载于:https://www.cnblogs.com/acm-jing/p/4314369.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值