The challenge of codevs1997 guardians

Source: Internet
Author: User

Title Description 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 common challenge, the challenges were followed. The first challenge has a property AI, which, if ai≥0, indicates that the challenge can be successfully followed by an AI-capable package; if Ai =-1, the challenge is to get a 1-size map fragment. 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 take all the pieces of the map to take away (no need to consider, just to complete all the n challenges after the backpack capacity enough to accommodate the map fragments can), 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 success for the 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.

Enter a description input Description

The first row of 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.

outputs description output Description

An integer that represents the probability of being calculated, forcing rounding to retain 6 decimal places.

sample input to sample

"Sample Input 1"
3 1 0
10 20 30
-1-1 2

"Sample Input 2"
5 1 2
36 44 13) 83 63
-1 2-1 2 1

Sample output Sample outputs

"Sample Output 1"
0.300000

"Sample Output 2"
0.980387

data size & Hint

In the first example, if the third challenge succeeds, if a victory in the first two games, the players have room to accommodate the resulting map fragments, if the challenge fails, there is no map fragments, regardless of whether it can be installed; If the third challenge fails, if the first two wins, there is no package to install the map fragments, If the first two games fail, the requirement of at least a successful L-time (L = 1) is not met. So the probability of finding the third challenge is the probability of winning.

For 100% of data, ensure 0≤k≤2000,0≤n≤200,-1≤ai≤1000,0≤l≤n,0≤pi≤100.

Source: Nescafe 17

Positive Solution: DP

Problem Solving Report:

Consider directDPtransfer probability, it's like a knapsack problem. F[i][j][k]represents the formerIChallenge, win the game.Jfield and capacity forkthe probability, note: capacity is greater thanNpart does not have any effect, so we can use a capacity of2xnrepresents the actualNof space, capacity forNrepresents the actual0,capacity of0indicates that the actual need also- Nof space. The transfer is also good to transfer, if this victory is multiplied by the probability of victory and gets a fragment or backpack, otherwise multiplied by the probability of failure. There is a very important problem, because we need to constrain the upper and lower bounds, the redundant parts do not need, so only write-off to ensure the correctness of the transfer. Just take a look. To not explode the space, scroll the array.

1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - using namespacestd; -typedefLong LongLL; the Const intMAXN =211; - intn,l,k; - Long DoubleP[maxn],ans; - intA[MAXN]; + Long Doublef[maxn][maxn][maxn*2];//Scrolling Array - //long double f[maxn][maxn][maxn*2];//F[i][j][k] Represents the first I field challenge, wins the probability of J field and volume K + //parts with a capacity greater than n have no effect A //A capacity of 2XN represents the actual space of N, the capacity of N represents the actual 0, the capacity of 0 means that the actual also needs-n space at  -InlineintGetint () - { -        intw=0, q=0;CharC=GetChar (); -         while((c<'0'|| C>'9') && c!='-') C=getchar ();if(c=='-') q=1, c=GetChar (); -         while(c>='0'&& c<='9') w=w*Ten+c-'0', C=getchar ();returnQ? -w:w; in } -  toInlinevoidWork () { +N=getint (); L=getint (); k=getint (); -      for(intI=1; i<=n;i++) scanf ("%LF", &p[i]), p[i]/=100.0; for(intI=1; i<=n;i++) a[i]=getint (); the     //for (int i=0;i<=n;i++) for (int j=n*2;j>=0;j--) f[0][i][j]=1; *f[0][0][n+min (n,k)]=1.0;inttag=1; $      for(intI=1; i<=n;i++) {Panax Notoginsengmemset (F[tag],0,sizeof(F[tag])); tag^=1;  -      for(intj=0; j<i;j++)  the          for(intk=n*2; k>=0; k--) { +f[tag^1][j+1][min (k+a[i],n*2)]+=f[tag][j][k]*P[i]; Af[tag^1][j][k]+=f[tag][j][k]* (1-p[i]); the         } +     } -tag^=1; for(inti=l;i<=n;i++) for(intj=n;j<=n*2; j + +) ans+=F[tag][i][j]; $     /*for (int i=0;i<n;i++)//can only write to turn out, because the upper and lower bounds need to control!!!  $ for (int j=0;j<=i;j++) - for (int k=n*2;k>=0;k--) {//Transfer past - //This victory the f[i+1][j+1][min (k+a[i+1],n*2)]+=f[i][j][k]*p[i+1]; - //This failure, nothingWuyi f[i+1][j][k]+=f[i][j][k]* (1-p[i+1]);  the         } -  Wu for (int i=l;i<=n;i++) - for (int j=n;j<=n*2;j++)//At least 0 to get out About Ans+=f[n][i][j];*/ $printf"%.6LF", ans); - } -  - intMain () A { + Work (); the   return 0; -}

The challenge of codevs1997 guardians

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.