HDU 2955 robberies (10 backpack adaptation)

Source: Internet
Author: User

 

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

 

 

 

Question:

The thief wants to steal money from the bank.

Give you the maximum probability of being caught, and n Banks

The N rows below represent the amount of money the bank has and the maximum probability of being arrested.

At this time, the key thing is how to write dynamic equations.

The 10 backpacks we learned are made up of two types: one is the maximum size of the backpack, and the other is the value and size of the items loaded into the backpack.

To simulate this process, first:

Use all bank money as the maximum volume of a backpack

The money of each bank is used as the volume of items.

So the probability of being captured is the value of an item.

Then we can easily introduce the dynamic equation we need:

DP [I] = max (DP [I], (DP [I-money] * (1-rp); // money: current bank money, RP: Current probability of being caught

The rest is the set template.

 

The AC code is as follows:

# Include <iostream> # include <stdio. h> using namespace STD; double DP [10050]; double RP; int num; double RP [10050]; int money [10050]; int sum; double max (double, double B) {If (A> B) return a; elsereturn B;} void zeroonepack (INT money, double RP) {int I; for (I = sum; i> = money; I --) DP [I] = max (DP [I], (DP [I-money] * (1-rp); // equation, storage probability (equivalent to value)} int main () {int case; scanf ("% d", & case); While (case --) {scanf ("% lf % d", & RP, & num); sum = 0; int I; memset (DP, 0, sizeof (DP )); for (I = 0; I <num; I ++) {scanf ("% d % lf", & money [I], & RP [I]); sum = sum + money [I]; // use all the bank's money as the total volume of the backpack} DP [0] = 1; for (I = 0; I <num; I ++) zeroonepack (money [I], RP [I]); // The money in each bank is treated as an item volume for (I = sum; I> = 0; I --) // reverse search {If (DP [I] >=( 1-rp) {printf ("% d \ n", I); break ;}}} return 0 ;}

 

 

 

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.