22179_CityRoad

2022-5-16 18:21| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506178184099-Problem List-采集的数据-后羿采集器.html

Pro.ID

22179

Title

City Road

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22179

AC

1

Submit

1

Ratio

100.00%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Long long ago, city Old was all around the water and was divided into M × N small square houses. The city Old had only two bridges, in the southwest comer and northeast comer. It's obvious that the citizens can have C( m+n, n ) different ways with shortest length, to go from one bridge to the other.

    As the city developed, bigger buildings came out and blocked some streets. These new buildings were always large rectangles combining many small houses. Since the new buildings may affect the number of shortest ways a lot, it’s you job now to recalculate the number.

    The city has M rows and N columns of houses, M+1 horizontal streets, and N+1 vertical streets. Suppose the house in the southwest comer is (1, 1), then the house in the northeast comer can be marked as (m, n). And then each new building can be described by its southwest comer(house) and its size(number of houses) in horizontal and vertical directions.

    The picture below shows that the city Old has 5×6 houses and one 3×2 building with its southwest comer located at (2, 4). The number of different shortest ways in the picture is 192.


    输入

    This problem has multiple test cases. In each test case, the first line is two integer m, n ( m×n ≤ 1,000,000 ) which indicate the size of city Old, in vertical and horizontal directions respectively. And the second line has one integer B ( B ≤ 1000 ) what is the number of the new buildings. After that there are B lines. Each line has four integers x, y, a, b, describing the southwest comer (x, y), the vertical size a, and the horizontal size b of the building. The buildings may be overlapped with each other. The input is terminated by a case with m×n=0, which should not be processed.

    输出

    Description

    Long long ago, city Old was all around the water and was divided into M × N small square houses. The city Old had only two bridges, in the southwest comer and northeast comer. It's obvious that the citizens can have C( m+n, n ) different ways with shortest length, to go from one bridge to the other.

    As the city developed, bigger buildings came out and blocked some streets. These new buildings were always large rectangles combining many small houses. Since the new buildings may affect the number of shortest ways a lot, it’s you job now to recalculate the number.

    The city has M rows and N columns of houses, M+1 horizontal streets, and N+1 vertical streets. Suppose the house in the southwest comer is (1, 1), then the house in the northeast comer can be marked as (m, n). And then each new building can be described by its southwest comer(house) and its size(number of houses) in horizontal and vertical directions.

    The picture below shows that the city Old has 5×6 houses and one 3×2 building with its southwest comer located at (2, 4). The number of different shortest ways in the picture is 192.


    Input

    This problem has multiple test cases. In each test case, the first line is two integer m, n ( m×n ≤ 1,000,000 ) which indicate the size of city Old, in vertical and horizontal directions respectively. And the second line has one integer B ( B ≤ 1000 ) what is the number of the new buildings. After that there are B lines. Each line has four integers x, y, a, b, describing the southwest comer (x, y), the vertical size a, and the horizontal size b of the building. The buildings may be overlapped with each other. The input is terminated by a case with m×n=0, which should not be processed.

    Output

    For each test case output one integer representing the number of shortest ways in a single line. This number is guaranteed to be less than 263.

    Sample Input

    5 6
    15 6
    2 4 3 25 6
    0 0

    Sample Output

    192

    Source

    样例输入

    5 6
    15 6
    2 4 3 25 6
    0 0

    样例输出

    192

    提示

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部