Ron's permutation is exposed to m examinations of the accompanying sort: (ri, pi). This means that components in range [1,ri] (as such, the prefix of length ri) have to be arranged in ascending request with the probability of pi. All examinations are acted in the same request wherein they are determined in the input data.    As an example, how about we take a gander at a

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Correct answer will be upvoted else Multiple Downvoted. Computer science.

Ron's permutation is exposed to m examinations of the accompanying sort: (ri, pi). This means that components in range [1,ri] (as such, the prefix of length ri) have to be arranged in ascending request with the probability of pi. All examinations are acted in the same request wherein they are determined in the input data. 

 

As an example, how about we take a gander at a permutation [4,2,1,5,3] and an investigation (3,0.6). After such a test with the probability of 60% the permutation will assume the structure [1,2,4,5,3] and with a 40% probability it will remain unchanged. 

 

You have to decide the probability of the permutation turning out to be totally arranged in ascending request after m trials. 

 

Input 

 

Each test contains at least one experiments. The main line contains the number of experiments t (1≤t≤100). 

 

The primary line of each experiment contains two integers n and m (1≤n,m≤105) — the length of the permutation and the number of trials, individually. 

 

The second line of each experiment contains n integers a1,a2,… ,an (1≤ai≤n) — substance of the permutation. 

 

The accompanying m lines of each experiment each contain an integer ri and a real number pi (1≤ri≤n,0≤pi≤1) — the length of the prefix and its probability being arranged. All probabilities are given with at most 6 decimal places. 

 

It is guaranteed that the amount of n and the amount of m doesn't surpass 105 (∑n,∑m≤105). 

 

Output 

 

For each experiment, print a solitary number — the probability that after all investigations the permutation becomes arranged in ascending request. Your answer will be considered right if its absolute or relative mistake doesn't surpass 10−6. 

 

Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and provided that |a−b|max(1,|b|)≤10−6.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Concept of Randomized Approximation Algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education