Escape Problem

本文介绍了一个基于递归算法的逃逸路径计算问题。主要内容是如何为著名的小偷Hamilton计算从银行抢劫现场到庇护所的不同逃逸路线数量,并考虑了不能重复经过同一交叉口及只能直行或右转的限制条件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

Hamilton, the famous thief, plans a bank robbery in L.A. When searching for the escape route, he takes two main factors into consideration. First, he cannot pass through any intersection twice since the police will set up force at any intersection after he passes it for the first time. Second, as, in America, vehicles are driven on the right side, it is too risk for Hamilton to take a left turn at intersections when escaping. So he will always drive straight ahead or turn right when he comes to a intersection.

Hamilton is planning his escape route. He pays you, his partner, to calculate the number of different ways which leads him to his shelter. He gives you the map of the city, which looks like grids, with only streets leading in East-West direction and South-North direction. His starting position is (0, 0) which is the South-West corner of the city and his shelter is located at (x, y) which stands for the intersection of the (x+1)th South-North direction street and the (y+1)th East-Wesst direction street. Moreover, when he starts at (0, 0), he is heading north, and of course, he can make a right turn there as well.

As the total number of different ways might be very large, you are asked to give the number's residue modulo 100000007.

输入

The first line of input contains N (N <=100), the number of test cases. Each of the following lines describes one test case. Each line consists of four integers, X, Y, x, y(0<X,Y≤2000, 0≤x≤X, 0≤y≤Y), which (X, Y) is the North-East corner of the city and (x, y) is the location of Hamilton's shelter. The famous thief, of course, cannot driver out of the city.

输出

For each test case, print one line with a single integer which is the corresponding answer.

样例输入
3
3 4 0 0
3 4 1 0
3 4 1 1
样例输出
1
13
16


The following is my answer 这是一个递归的问题, 计算的时候每次对 (x + 1, y) , (x + 2, y) .... (X, y)  为参考原点 (0,0) 生成新的坐标系作递归计算。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值