F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Min-Max

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 82    Accepted Submission(s): 25


Problem Description
This problem is about two very common functions $~min(a, b)~$ and $~max(a, b)~$, the function $~min(a, b)~$ returns the smaller of $~a~$ and $~b~$, and function $~max(a, b)~$ returns the bigger one.

Now, you are given a permutation $a_1, a_2,...,a_n$, and $~m~$ expressions, the $~ith~$ expression will one of the follows

1. $b_i = min(X, Y)$
2. $b_i = max(X, Y)$

Where $~X~$, $~Y~$ can be $~a_j(1 \leq j \leq n)~$ or $~b_j(1 \leq j <i)~$.
And the questions is, if we randomly choose permutation $a_1, a_2,...,a_n$ with equal probability, what is the expected value of $~b_m~$.
 

Input
The input data contains server test case(end with EOF), for each test case
The first line contain two integer $~n~$ and $~m~$. ($2 \leq n \leq 15, 1 \leq m \leq 1000$)
Then following $~m~$ lines, the $ith$ line describe the right side of the $~ith~$ expression(note that the left side is always be $~b_i=~$), and is one of the follows:
1. $min\, tp_0\, id_0\, tp_1\, id_1$
2. $max\, tp_0\, id_0\, tp_1\, id_1$
The pair $(tp, id)$ describe one variable, if tp is 'a', then it means $~a_{id}~$, else tp will be 'b', and it means $~b_{id}~$
 

Output
One line contain one integer $E[b_m] \times n!$, it can be prove, that the result always be an integer.
 

Sample Input
3 2 max a 2 a 3 min a 1 b 1 3 2 max a 2 a 3 max a 1 b 1
 

Sample Output
10 18
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 17:26:41, Gzip enabled