Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

LEEXAMS - Editorial

$
0
0

Problem Link:

Practice
Contest

Difficulty:

Easy

Pre-requisites:

High School Maths

Problem:

Given n tickets, ith ticket can be labelled
* Ai with probability Pi percent.
* Bi with probability 100-Pi percent.
Find the probability that all tickets get distinct numbers.

Explanation:

The most important thing to notice about this problem was that while there can be upto 50 tickets, at most 16 labels are available. Therefore, by pigeon hole principle, if the number of tickets is more than 16, then at least one label will be shared by two or more tickets. Hence, the probability is non-zero only if n≤16.

Now, it is clear that the number of ways of allotting labels to tickets is 2^n, because each ticket can have one of the two labels. Therefore, we could brute force over all possible allotments of tickets in O(2^n) time, and for each assignment, find
* probability of that assignment
* If the assignment is valid or not
Calculate the sum of probability of all valid assignments, and that is your answer.

Find pseudo code of a recursive implementation of the solution below. There can be many different ways to implement the same thing, as will be apparent in setters/testers/editorialist's solutions.
// all tickets from 0 to i-1 have been assigned labels. double solve(int i, bool labels-used[16], double probability-so-far) if i == n return probability-so-far double ans = 0 for (l,p) in [(A[i], p[i]), (B[i], 100-P[i])]: if labels-used[l-1] == true continue labels-used[l-1] = true ans += solve(i+1, labels-used, probability-so-far*p/100.0) labels-used[l-1] = false return ans
bool labels[16] = {false}; if n<=16 finalans = solve(0, labels, 1) else finalans = 0

Setter's Solution:

Can be found here

Tester's Solution:

  1. Mahbub's code
  2. Sergey's code

Editorialist's Solution:

Can be found here


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>