编程介的小学生 2017-03-11 11:41 采纳率: 20.5%
浏览 921
已采纳

Dinner Is Ready

Dinner is ready! WishingBone's family rush to the table. WishingBone's mother has prepared many delicious bones. WishingBone has several brothers, namely WishingTwoBones, WishingThreeBones. WishingBone wants at least one bone, WishingTwoBones two and WishingThreeBones three. :-P But as they are not too greedy (or they want to keep shape), they decide that they want at most twice of their minimal requirement. Now let's suppose mother has prepared 7 bones, one way to distribute them is 2-2-3, the other two ways are 1-3-3 and 1-2-4. Of course mother doesn't want to waste any bones, so if she had prepared 13 bones, she would end up without any feasible distribution.

As curious as WishingBone, mother wants to know how many different ways she can distribute those bones.

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 contains two integers n and m (0 < n <= 8, 0 < m), where n is the number of children and m is the number of bones mother has prepared.

The next n lines have two integers mini and maxi (0 <= mini <= maxi <= m), which is the minimal and maximal requirement of the ith child.

Output

N integers which are the numbers of ways to distribute the m bones, one per line.

Sample Input

2
3 7
1 2
2 4
3 6
3 13
1 2
2 4
3 6

Sample Output

3
0

  • 写回答

1条回答 默认 最新

  • devmiao 2017-03-11 15:02
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分