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

numbers

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 196608/196608 K (Java/Others)
Total Submission(s): 309    Accepted Submission(s): 109


Problem Description
Now you have a stack and $n$ numbers $1,2,3,бн,n$. These $n$ numbers are pushed in the order and popped if the number is at the top of the stack. You can read the sample to get more details.
This question is quite easy. Therefore I must give you some limits.
There are $m$ limits, each is expressed as a pair$<A,B>$ means the number $A$ must be popped before $B$.
Could you tell me the number of ways that are legal in these limits?
I know the answer may be so large, so you can just tell me the answer mod $1000000007({10}^{9}+7)$.
 

Input
The first line contains an integer $T$(about 5),indicating the number of cases.
Each test case begins with two integers $n(1 \leq n \leq 300)$ and $m(1 \leq m \leq 90000)$.
Next $m$ lines contains two integers $A$ and $B(1 \leq A \leq n,1 \leq B \leq n)$
(P.S. there may be the same limits or contradict limits.)
 

Output
For each case, output an integer means the answer mod $1000000007$.
 

Sample Input
5 1 0 5 0 3 2 1 2 2 3 3 2 2 1 2 3 3 3 1 2 2 3 3 1
 

Sample Output
1 42 1 2 0
 

Hint
The only legal pop-sequence of case 3 is 1,2,3.
The legal pop-sequences of case 4 are 2,3,1 and 2,1,3.
 

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-12-04 00:48:37, Gzip enabled