您的位置:首页 > 其它

HDU 2955 Robberies

2013-09-21 21:50 239 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2955

逃脱机率 = 1 - 总的被捉机率

#include <iostream>
using namespace std;
double dp[10010]={0};
int ans;
void ZeroOnPack(int cost,double weight,int V,double P)
{
for(int i=V;i>=cost;i--)
{
dp[i] = max(dp[i],dp[i-cost]*(1-weight));
if(dp[i]>=1-P&&ans<i)
{
ans = i;
}
//cout<<"可取"<<i<<"总钱"<<V<<" "<<dp[i]<<endl;
}
}
int main(int argc, const char *argv[])
{
int T;
//freopen("input.txt","r",stdin);
cin>>T;
while(T--)
{
ans = 0;
double P;
int N;
int V = 0;
memset(dp,0,sizeof(dp));
dp[0]=1;
cin>>P>>N;
for(int i=0;i<N;i++)
{
float weight;
int val;
cin>>val>>weight;
V+=val;
ZeroOnPack(val,weight,V,P);
}
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: