编程介的小学生 2017-09-08 04:56 采纳率: 20.5%
浏览 845
已采纳

Game Of Logic

This Christmas WishingBone has got some new toys which are real cool. This is one of them.

On a large board there fixed many logic units and lines between them. They are called bone logic which is composed of one input, one output and a nice looking button. Only after the input becomes 1 and the button is pressed will it output 1, otherwise its output is 0. Bone logics can be interconnected in series or in parallel. A legal game board is shown below.

In the figure there are 3 bone logics. The red one and the blue one is interconnected in parallel and they are together interconnected in series with the green one. All the bone logics are arranged so that their input end is on the left and output end is on the right. All the connection points are labeled from 1 to m, where 1 is the single input of the board and m is the single output of the board. Note that an n-to-1 connection point like point 2 in the figure uses AND logic that produces a 1 signal only if all the inputs become 1.

Initially all the signals are 0 except input of the board (point 1). Your goal is to press n bone logics sequentially to turn the output of the board (point m) into 1. A bone can be pressed only if the signal comes into it become 1. And all bones will be pressed exactly once. In the example above, one way to achieve this is to press red-blue-green; another possibility is to press blue-red-green. Though it is rather easy to figure one way out, WishingBone is curious about how many ways on earth he can solve a particular board configuration.

Input

The first line of input is a positive integer N <= 100, which is the number of test cases.

The first line of each case is two integers n and m (0 < n <= 100, 2 <= m <= n+1), which are the number of bone logics and connection points.

The following n lines contains two integers li ri (0 < li, ri <= m) indicating the connection point on the left and right of bone logic i.

The input board configuration is always legal, and has at least one way to achieve the goal.

Output

N integers which are the numbers of ways to achieve the goal on the N board configurations, one per line.

Sample Input

3
3 3
1 2
1 2
2 3
3 4
1 2
2 3
3 4
4 3
1 2
1 2
2 3
1 3

Sample Output

2
1
8

  • 写回答

1条回答

  • threenewbee 2017-09-23 15:26
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容