HDU I need A offer!

Source: Internet
Author: User

This question is a very basic 0/1 knapsack problem, in order to make the solution is very simple, can be asked in the topic the maximum probability of conversion into the minimum probability of admission, so 1-dp[n] is the maximum probability of at least one offer. State equation

is: Dp[j]=min{dp[j],dp[j-price[i]]*chance[i]};

1#include"iostream"2#include"stdio.h"3#include"algorithm"4#include"string.h"5#include"Cmath"6#include"Queue"7 #defineMX 100058 using namespacestd;9 intPRICE[MX];Ten DoubleCHANCE[MX]; One DoubleDP[MX]; A intMain () - { -     intn,m,i,j,k; the      while(cin>>n>>m,n| |m) -     { -          for(i=1; i<=m;i++) -         { +Cin>>price[i]>>Chance[i]; -chance[i]=1-Chance[i]; +         } A          for(i=0; i<=n;i++) dp[i]=1; at          for(i=1; i<=m;i++) -         { -              for(j=n;j>=price[i];j--) -             { -                 if(Dp[j]>dp[j-price[i]]*chance[i]) dp[j]=dp[j-price[i]]*Chance[i]; -             } in         } -printf"%.1lf%%\n",(1-dp[n]) * -); to     } +     return 0; -}
View Code

HDU I need A offer!

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.