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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘