hdu 1203 dp(关于概率的```背包?)

题意:一个人手里有一笔钱 n ,有 m 所大学,分别知道这些大学的投简历花费和被录取概率,因为钱数有限,只能投一部分学校,问被录取的概率最大有多大。

这题除去计算概率以外就是一个 0 1 背包问题,所以可以完全按照 0 1 背包的方法做,只是将价值计算变成概率计算而已

dp [ j ] 表示花费了 j 时概率的最大值;

当遍历到第 i 个大学时,第 i 个大学花费 a ,被录取的概率 b ,当前被录取概率为 dp;那个加上第 i 所大学,概率就是:

(原本被录取概率)+(原本未被录取概率)* b ;

所以 dp [ j ] = max ( dp [ j ] , dp [ j - a ] + ( 1 - dp [ j - a ] * b ) );

0 1 背包毕竟做了这么多遍,不会才不应该的。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define max(a,b) a>b?a:b
 4 int a;
 5 double b,dp[10001];
 6
 7 int main(){
 8     int n,m;
 9     while(scanf("%d%d",&n,&m)!=EOF&&(n!=0||m!=0)){
10         int i,j;
11         double ans=0;
12         memset(dp,0,sizeof(dp));
13         for(i=1;i<=m;i++){
14             scanf("%d%lf",&a,&b);
15             for(j=n;j>=a;j--){
16                 dp[j]=max(dp[j],dp[j-a]+(1-dp[j-a])*b);
17                 ans=max(ans,dp[j]);
18             }
19         }
20         printf("%.1lf%%\n",ans*100);
21     }
22     return 0;
23 }

时间: 2025-01-04 06:23:01

hdu 1203 dp(关于概率的```背包?)的相关文章

hdu 1203 I NEED A OFFER! &lt;背包的变形&gt;

I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20496    Accepted Submission(s): 8183 Problem Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了.要申请国外的任何大学,你都要

hdu 1203 dp背包问题

一个背包问题将价值变成了概率,求最小的一个收不到的概率,然后用1减去就可以啦! #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string>

hdu 1203 概率+01背包

I NEED A OFFER! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1203 Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了.要申请国外的任何大学,你都要交纳一定的申请费用,这可是很惊人的.Speakless没有多少钱,总共只攒了n万美元

hdu 1203 01背包 I need a offer

hdu 1203  01背包  I need a offer 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1203 题目大意:给你每个学校得到offer的概率以及花费,给定money,求得到至少一份offer的最大概率. 简单的01背包 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 6 double

HDU 4652 Dice (概率DP)

Dice Problem Description You have a dice with m faces, each face contains a distinct number. We assume when we tossing the dice, each face will occur randomly and uniformly. Now you have T query to answer, each query has one of the following form: 0

HDU 3366 Passage (概率DP)

Passage Problem Description Bill is a millionaire. But unfortunately he was trapped in a castle. There are only n passages to go out. For any passage i (1<=i<=n), Pi (0<=Pi<=1) denotes the probability that Bill will escape from this castle saf

hdu 2955 Robberies(概率背包)

Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22658    Accepted Submission(s): 8358 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that

[ACM] HDU 4576 Robot (概率DP,滚动数组)

Robot Problem Description Michael has a telecontrol robot. One day he put the robot on a loop with n cells. The cells are numbered from 1 to n clockwise. At first the robot is in cell 1. Then Michael uses a remote control to send m commands to the ro

hdu 5389 dp类似背包

http://acm.hdu.edu.cn/showproblem.php?pid=5389 Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (you may hear about ever17?) and developed by Chunsoft. Stilwell is enjoying the first chapter of this