hdu Robberies 2955 01背包

第一次果断吧概率当成背包了,放大100000倍,而且强多家银行的概率是相乘,不是相加啊

将抢的钱数当成背包转移公式:

dp[j]表示在能抢到j百万的时候成功的最大概率

dp[j]=max(dp[j],dp[j-m[i]]*(1-p_bank[i]));

/*************************************************************************
	> File Name: hdu2955.cpp
	> Author: yang
	> Mail:[email protected]
	> Created Time: 2014年08月23日 星期六 10:57:47
 ************************************************************************/

#include<iostream>
#include<stdio.h>
#include<memory.h>
using namespace std;
#define N 105
int main(){
//	freopen("in.txt","r",stdin);
	int t,n;
	double dp[10010];
	cin>>t;
	int m[N];
	double p_bank[N],p_thief;
	while(t--){
		cin>>p_thief>>n;
		int sum=0;
		for(int i=0;i<n;i++){
			cin>>m[i]>>p_bank[i];
			sum+=m[i];
		}
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		for(int i=0;i<n;i++){
			for(int j=sum;j>=m[i];j--){
				dp[j]=max(dp[j],dp[j-m[i]]*(1-p_bank[i]));
			}
		}
		for(int i=sum;i>=0;i--){
			if(dp[i]>(1-p_thief)){
				printf("%d\n",i);
				break;
			}
		}
	}
}
时间: 2024-08-28 03:34:30

hdu Robberies 2955 01背包的相关文章

Robberies hdu 2955 01背包

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

Robberies(01背包)

Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only

Jam&#39;s balance HDU - 5616 (01背包基础题)

Jim has a balance and N weights. (1≤N≤20) The balance can only tell whether things on different side are the same weight. Weights can be put on left side or right side arbitrarily. Please tell whether the balance can measure an object of weight M. In

hdu 2955 Robberies(01背包)

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

hdu2955 Robberies (01背包)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because t

hdu 2602 dp 01背包

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 这题是非常标准的01背包,没啥特殊的地方,很简单 代码: #include <bits/stdc++.h> #define MAXS 1006 using namespace std; int value[MAXS]; int main () { int T; int n,m_v,v; int f[MAXS] ; cin >> T; while(T--) { memset(f,

HDU - 2639(01背包求第K大值)

传送门 题意:it will be a strictly decreasing sequence from the 1st maximum , 2nd maximum .. to the K-th maximum.  If the total number of different values is less than K,just ouput 0. 输入:T组数据 体积V 要求的K    N , V, K(N <= 100 , V <= 1000 , K <= 30) 各项价值 各项

hdu 1171 Big Event in HDU(dp 01背包 母函数)

01背包 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<iostream> using namespace std; int v[100],m[100]; int dp[300000]; int main() { int n; int i,j,k; while(scanf("%d",&n)!=EOF) {

hdu 3466 排序01背包

也是好题,带限制的01背包,先排序,再背包 这题因为涉及到q,所以不能直接就01背包了.因为如果一个物品是5 9,一个物品是5 6,对第一个进行背包的时候只有dp[9],dp[10],…,dp[m],再对第二个进行背包的时候,如果是普通的,应该会借用前面的dp[8],dp[7]之类的,但是现在这些值都是0,所以会导致结果出错.于是要想到只有后面要用的值前面都可以得到,那么才不会出错.设A:p1,q1 B:p2,q2,如果先A后B,则至少需要p1+q2的容量,如果先B后A,至少需要p2+q1的容量