QOJ.ac

QOJ

Time Limit: 6 s - 12 s Memory Limit: 1024 MB Total points: 30

#5902. Upstairs/Downstairs

الإحصائيات

Problem

Konstantin and Ilia live in the same house. Konstantin lives upstairs, and enjoys activities that involve jumping, moving furniture around, and - in general - making noise. Ilia lives downstairs, and enjoys sleep.

In order to have a good evening, Konstantin wants to do at least K activities. Last night, Ilia asked Konstantin to try not to wake him up; and because Konstantin is a very nice neighbor, he agreed. Unfortunately, he took Ilia's request a bit too literally, and he will choose his activities in such a way as to minimize the probability that Ilia is woken up after falling asleep.

Each possible activity for Konstantin has an associated probability ai/bi. If Konstantin performs this activity, then at the end of it, Ilia will be awake with probability ai/bi, and asleep otherwise, regardless of whether he was asleep at the start. Moreover, for each possible activity Konstantin can perform it at most ci times (more than that would be boring, and Konstantin won't have a good evening if he's bored).

Konstantin wants to choose a number of activities to do, in order, so that:

The total number of activities done is at least K. The ith activity is performed no more than ci times. The probability Q that Ilia is woken up one or more times during the course of the activities is as small as possible. Ilia starts awake, so in order for him to be woken up, he must be asleep at the end of some activity, and then awake at the end of the next activity.

What is the smallest Q Konstantin can achieve while having a good evening? Note that Konstantin cannot tell whether Ilia is awake or asleep, and so he cannot adapt his activities using that information.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a pair of integers, N, K, on a line by themselves. N lines follow, each of which represents an activity that Konstantin can choose. Each of those lines is formatted as "ai/bi ci", indicating that there is an activity which would leave Ilia awake with probability ai/bi and which Konstantin can perform at most ci times without being bored.

Output

For each test case, output one line containing "Case #x: Q", where x is the case number (starting from 1) and Q is the smallest probability of Ilia waking up during the course of the activities that Konstantin performs. Answers with absolute or relative error no larger than 10-6 will be accepted.

Limits

Memory limit: 1GB.

1 ≤ T ≤ 100.

0 ≤ aibi ≤ 1000000 for all i.

1 ≤ bi and 1 ≤ ci for all i.

1 ≤ K ≤ the sum of all ci in that test case.

Test set 1 (Visible Verdict; 13 Points)

Time limit: 30 6 seconds.

1 ≤ N ≤ 100.

The sum of all ci is no larger than 100 in each test case.

Test set 2 (Hidden Verdict; 17 Points)

Time limit: 60 12 seconds.

1 ≤ N ≤ 10000.

The sum of all ci is no larger than 106 in each test case.

Sample

3
4 1
1/2 3
1/5 2
2/5 1
2/2 2
3 2
1/2 2
1/3 2
3/4 2
3 3
99/100 1
1/2 2
1/50 3
Case #1: 0.000000000
Case #2: 0.083333333
Case #3: 0.015000000
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.