HDU robberies 2955 01 backpack

Source: Internet
Author: User

For the first time, the probability is regarded as a backpack, which is increased by 100000 times. In addition, the probability of many strong banks is multiplied, not the sum.

Take the amount of money you want to grab as a backpack transfer formula:

DP [J] indicates the maximum probability of success when the user can grab J million

 
DP [J] = max (DP [J], DP [J-M [I] * (1-p_bank [I]);

/*************************************** * *********************************> File Name: hdu2955.cpp> author: Yang> mail: [email protected]> created time: saturday, August 23, 2014 10:57:47 ************************************* * *********************************/# include <iostream> # include <stdio. h> # include <memory. h> using namespace STD; # define n 105int main () {// freopen ("in.txt", "r", stdin); int t, n; double DP [1, 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 ;}}}}


HDU robberies 2955 01 backpack

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.