Regionals >> Asia-tehran >> 7527-funfair "greedy" "DP"

Source: Internet
Author: User

7527-funfair

Topic Links: 7527

The main topic: play a Level game, the initial X-yuan, a total of n off, their choice of K-off, as well as the order of clearance. When I close, win the probability of Pi, won the Ai Yuan after winning, lost, then lose Li * x money. Ask how to choose off and the order of the level so that the final amount of money to expect the most.

Topic idea: First, need to sort, this can ensure that the first i+1 off after I close, and then to DP, I close or not to take.

Sort by: We can know that when I close the first

赢: (Ai + x) * Pi输: (1 - Pi)(1 - Li) * x相加合并一下得到(1 - Li + LiPi) * x + Ai * Pi假设 c = (1 - Li + LiPi)    d = Ai * Pi即: cx + d那么,在考虑先过A关还是B关的时候,有两种可能性,先过A关:c2 * (c1*x+d1) + d2;先过B关:c1 * (c2*x+d2) + d1;假设A大于B,c2 * (c1*x+d1) + d2 > c1 * (c2*x+d2) + d1化简得到,d1/(c1-1) < d2/(c2-1)

So: Sort by d1/(c1-1) < d2/(c2-1).

Attention:
1. When sorting, you need to consider the case of C equals 1 (denominator cannot be 0)
When the 2.p,l is in, divide by 100 (because they are percentages)

The last DP to handle it!

Here's the code:

#include <iostream>#include <iomanip>#include <fstream>#include <sstream>#include <cmath>#include <cstdio>#include <cstring>#include <cctype>#include <algorithm>#include <functional>#include <numeric>#include <string>#include <set>#include <map>#include <stack>#include <vector>#include <queue>#include <deque>#include <list>using namespace STD;#define EPS 1e-6structnode{DoubleA,l,p,c,d,s;} g[ the];BOOLCMP (Node A, Node B) {if(A.C = =1|| B.C = =1)returnA.C < B.C;//Compare pits!     returnA.S > B.S;}Doubledp[ the][ the];intMain () {intN,k,x; while(Cin>> N >> k >> x) {if(n = =0&& k = =0&& x = =0) Break;memset(DP,0,sizeof(DP));memset(g,0,sizeof(g)); for(inti =0; I < n; i++) {Cin>> g[i].a >> g[i].l >> g[i].p; G[I].L/= -; G[I].P/= -; G[I].C =1-G[I].L + g[i].l * G[I].P;            G[I].D = g[i].a * G[I].P; G[I].S = G[I].D/(G[I].C-1); } sort (g,g + n,cmp); for(inti =0; I < n; i++) dp[i][0] = x; for(inti =0; I < n; i++)//I choose not to select an activity{dp[i][1] = max (x * g[i].c + g[i].d,dp[i][1]); for(intL =0; l < i; l++)//In the first L activities{ for(intj =2; J <= min (l +2, k); J + +)//Selected J{Dp[i][j] = max (Dp[i][j],dp[l][j-1] * g[i].c + G[I].D); }            }        }DoubleAns =0; for(inti =0; I < n; i++) ans = max (Dp[i][k],ans);printf("%.2f\n", ans); }}

Attach several sets of test data:

/ * input * /5 3  - $  the  - the  $ 7 A  in Panax Notoginseng -  the  $ -  About  -Ten 5  + -  the  - in  A  A $  -  - the 98  the -  -  at $ 98  the -  -  the the  the  the -  the  the $  A  + - 1 Ten A 94  +Ten  at  the -  -  the -  -  the -  -  Wu the  -  the A  -  - -  the  the $ 4  * -  the  the *  the  + the  the  - +  -  - -  -  - the 4  thePanax Notoginseng  the  - -  -  - the  - Ten in  the  A - 7  the - 5 Ten in  -  A Wu 8  - -  in  - the  the 3 -  A  in the 4  - the 2  the the  the  the the  A  - -  -  - the  -  - -  -  the the  One  the -  - 94 -  -  the the  the 3 -  -  + at  the  + $  the  About - 0  the/ * Output * /90.67860.3979.80213.04

Regionals >> Asia-tehran >> 7527-funfair "greedy" "DP"

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.