City Road

City Road

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 14   Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem 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 corner and northeast corner. 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 corner is (1, 1), then the house in the northeast corner can be marked as (m, n). And then each new building can be described by its southwest corner(house) and its size(number of houses) in horizontal and vertical directions.

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 corner (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 2^63.

Sample Input

5 6
1
2 4 3 2
0 0

Sample Output

192
#include<iostream>
#include<string.h>
using namespace std;
__int64 arr[2000000];
__int64 fla[2000000];
int main()
{
 __int64 m,n,i,j,b,x,y,c,d;
 while(scanf("%I64d %I64d",&m,&n)&&m*n)
 {
   memset(fla,0,sizeof(fla));
   memset(arr,0,sizeof(arr));
   m++;n++;
         scanf("%I64d",&b);
    while(b--)
    {
     scanf("%I64d %I64d %I64d %I64d",&x,&y,&c,&d);
     c--;d--;
     for(i=x;i<x+c;i++)
     {
      for(j=y;j<y+d;j++)
      {
      fla[i*n+j]=1;
      }
     }
    }
    for(i=0;i<m;i++)
    {
     for(j=0;j<n;j++)
     {
      if(i==0||j==0)  {arr[i*n+j]=1;continue;}
      if(fla[i*n+j]) arr[i*n+j]=0;
      else arr[i*n+j]=arr[i*n+j-1]+arr[(i-1)*n+j];
     }
    }
   printf("%I64d\n",arr[m*n-1]);
 }
}

转载于:https://www.cnblogs.com/ffhuguang/archive/2012/11/12/2767224.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值