Hdu2955

//Robberies
/*思路比较巧,如果直接根据题意去想,用被捕的概率来做就比较困难;
基本思路:以钱为容量,在钱相同的情况下逃跑成功的概率要最大*/

#include<stdio.h>
#include<string.h>

float max(float a,float b);

int main()
{
	int t,n,m[105],sum,r;
	float pro,p[105],dp[10005];
	int i,j;
	while(scanf("%d",&t)!=EOF)
	{
		while(t--)
		{
			sum=0;
			memset(dp,0,sizeof(dp));
			dp[0]=1;
			scanf("%f%d",&pro,&n);
			for(i=0;i<n;i++)
			{
				scanf("%d%f",&m[i],&p[i]);
				p[i]=1-p[i];
				sum+=m[i];
			}
			for(i=0;i<n;i++)
			{
				for(j=sum;j>=0;j--)
				{
					dp[j]=max(dp[j],dp[j-m[i]]*p[i]);
				}
			}
			for(i=sum;i>=0;i--)
			{
				if(dp[i]>=(1-pro))
				{
					r=i;
					break;
				}
			}
			printf("%d\n",r);
		}
	}
	return 0;
}

float max(float a,float b){
	return(a>b?a:b);
}
时间: 2024-10-14 10:09:36

Hdu2955的相关文章

01背包水题篇之 HDU2955——Robberies

原来是想dp[i],表示不被抓概率为i所能抢到的最大钱(概率1-100) 后来看了别人的博客是dp[i]表示抢了i钱最大的不被抓概率,嗯~,弱菜水题都刷不动. 那么状态转移方程就是 dp[i]=max(dp[i],dp[i-money]*p),初始化dp(0~maxn)为0,dp[0]=1(1毛钱都没抢你抓个毛线啊,哥是良民~) 又是贴代码环节~ <span style="font-size:18px;">#include<iostream> #include&

hdu2955 Robberies

转载请注明出处: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

【hdu2955】 Robberies 01背包

hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在给定一个概率P,表示盗贼愿意冒险抢劫所能承受的最大被抓概率. 思路:首先用1减去被抓概率,得到安全概率.那抢劫了多家银行后的安全概率就是这些银行各自的安全概率连乘起来.其实是01背包的变种, dp[j] 表示获得金额 j 时的安全概率.这里用滚动数组,得方程  dp[j] = max(dp[j], dp[i-a[i

hdu-2955 Robberies

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 for a short while,

HDU2955 背包DP

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

hdu2955(变形01背包)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 分析:被抓概率可以转换成安全概率,Roy的安全概率大于1-P时都是安全的. 抢劫的金额为0时,肯定是安全的,所以dp[0]=1;其他金额初始为最危险的所以概率全为0: #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <algorith

HDU2955(01背包)

Robberies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18064    Accepted Submission(s): 6671 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

HDU2955 01背包变体 xingxing在努力

这道题的题意是小偷要去偷N家银行, 每家银行都有一个钱款数额Mi和被抓概率pi, 求小偷被抓的概率小于P的情况下所能偷到的钱数额的最大值(每家银行最多偷一次),由于每家银行最多偷一次, 所以这个题可以用01背包的思想来求解, 又因为小偷被抓会有很多种情况,并不好算,因此我们用他的反面小偷成功逃脱来算?这样题目就成了小偷在成功逃脱的概率大于1-P的情况下所能偷到的钱数最大值..记f[i][j]为小偷在前i家银行恰好偷了j块钱成功逃脱的 概率最大值, 那么f[i][j] = max(f[i-1][j