Hdu-2955 (01 backpack + reverse thinking + questions)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2955

Train of Thought: note that P and M [I] are the probability of being caught and cannot be used directly. They need to be converted to the probability of escaping, and then the obtained money is regarded as the volume of the backpack and then solved.

#include<iostream>#include<cstdio>#include<cstring>using namespace std;double p,vol[120],dp[12000]; int n,t,cost[120];int main(void){    int i,j,sum;    cin>>t;    while(t--)    {        memset(dp,0,sizeof(dp));        sum=0;        dp[0]=1;        cin>>p>>n;        p=1.0-p;        for(i=0;i<n;i++) cin>>cost[i]>>vol[i],sum+=cost[i],vol[i]=1.0-vol[i];        for(i=0;i<n;i++)        {            for(j=sum;j>=cost[i];j--)            dp[j]=max(dp[j],dp[j-cost[i]]*vol[i]);        }        for(i=sum;i>=0;i--)        {            if(dp[i]>=p) break;        }        cout<<i<<endl;    }    return 0;}

 

Hdu-2955 (01 backpack + reverse thinking + questions)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.