编程介的小学生 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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!