Defender's challenge: three-dimensional DP

Source: Internet
Author: User

Guardians ' Challenge
difficulty level: C; programming language: Unlimited; run time limit: 1000ms; run space limit: 262144KB; code length limit: 2000000B
Question Description
opening the gates of the Black magician Vani, the players searched aimlessly on the maze of roads to find the location of the prison where the Applepi were held. Suddenly, a bright light flashed through the front. "I, Nizem, are guardians of the Temple of the Dark arts." If you can pass my challenge, then you can take the map of the Temple of the Black magic ... "in a moment, the players were sent to a ring, initially surrounded by a bag of K-capacity. Showdown a total of N challenges, the challenges in turn. The item I challenge has an attribute AI, if ai>=0, indicates that the challenge can be achieved after the success of a capacity of the AI package; if ai=-1, this challenge can be achieved after a successful 1 map fragment size. Map fragments must be packed in the bag to bring out the ring, the bag does not have to be full, but the players must be "all of the obtained" map fragments are taken away (no need to consider, just to complete all the n challenges after the backpack capacity enough to accommodate the map fragments can be), in order to spell out the complete map. And they have to at least challenge the success L times to get out of the ring. When the players were helpless, the good guardians Nizem helped to estimate the probability of success for each challenge, and the probability of the success of the first I challenge was pi%. Now, ask your help to predict the probability that the players will be able to take their map fragments out of the ring.

input
The first line is three integers N, L, K.
The second row n real numbers, and the first real pi represents the percentage of the success of the first I challenge.
The third row n integers, the i integer AI represents the attribute value of the item I challenge.
Output
An integer that represents the probability that is calculated, rounded to retain 6 decimal places.
Input Example
3 1 0
Ten
-1-1 2
Sample Output
0.300000
Other Notes
data range: 0<=k<=2000,0<=n<=200,-1<=ai<=1000,0<=l<=n,0<=pi<=100.

--------------------------------------------------------------------------------------------------------------- -----------------------------------

The title is as above.

This problem was learned by Hzwer to come out. At first, I think the problem of negative subscript is still the probability of how to calculate, after seeing that this is not a thing.

First sort the challenge, then the DP probability, we use f[i][j][k] to represent the I challenge to win the J field when there is K space probability , and finally add up to come out

Data is not small, directly according to the topic definition of three-dimensional array space is not enough, see n<=200 after the discovery of all more than 200 of the data can be ignored ...

Not much to say the sticker code:

1#include <iostream>2 using namespacestd;3 Doublef[205][205][205],ans;4 structhh{DoublePintV;} a[205];5 BOOL operator< (WJH A,wjh b) {returnA.v>B.V;}6 intRead ()7 {8     intx=0, f=1;CharCh=GetChar ();9      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}Ten      while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} One     returnx*F; A } - intMain () - { the     intn,l,k,i,j,k; -N=read (); L=read (); k=read (); -      for(i=1; i<=n;i++) {cin>>a[i].p;a[i].p/= -;} -      for(i=1; i<=n;i++) a[i].v=read (); +Sort (A +1, a+n+1); f[0][0][min (K, $)]=1; -      for(i=0; i<n;i++) for(k=0; k<=i;k++) for(j=0; j<=n;j++) +     { Af[i+1][k][j]+=f[i][k][j]* (1-a[i+1].P); at         intt=j+a[i+1].V;if(t<0)Continue; -T=min (t,n); f[i+1][k+1][t]+=f[i][k][j]*a[i+1].P;  -     } -      for(i=0; i<=n;i++) for(j=l;j<=n;j++) ans+=F[n][j][i]; -printf"%.6LF", ans); -     //System ("pause"); in     return 0; -}
View Code

Defender's challenge: three-dimensional 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.