国防科大校赛决赛-final(镜像赛) Problem C: XueXX and Chessboard

Description
XueXX is a clever boy. And he always likes to do something with chessboard. What an interesting hobby!
Now XueXX is in a n*m chessboard, and he needs to go from (1,1) to (n,m). There are also some obstacles(障碍) in the chessboard, which he cannot move to. He wants to know how many ways he can get to the end point. Can you help him? Since the result is so huge, you need to mod the result by 1,000,000,007.
Input

The first line of input contains the number of test cases T. The descriptions of the test cases follow: The first line of each test case contains three integers n, m, k (1 <= n, m <= 1000, 0 < k <= 1000), respectively standing for the row number and the column number and the number of the obstacles. Then follows k lines , and each line contains two integer xi, yi (1 <= xi <= n, 1 <= yi <= m) , respectively standing for the coordinate(坐标) of the i-th obstacle.
Output

For each test case, output a single line containing the result (mod by 1,000,000,007).
Sample Input

3
5 5 0
1 1 0
3 3 1
2 2

Sample Output

70
1
2

HINT

#include"iostream"
#include"cstdio"
#include"cstring" 
using namespace std;
#define N 1010
#define M 1000000007
long long dp[N][N],xi,yi;
int main(){
    int t,n,m,i,j,k,flag;
    scanf("%d",&t);
    while(t--){
        scanf("%d %d %d",&n,&m,&k);
        memset(dp,0,sizeof(dp));
//      for(i=1;i<=n;i++){
//          dp[i][1] = 1;
//      }
//      for(i=1;i<=m;i++){
//          dp[1][i] = 1;
//      }
        dp[1][1] = 1;
        while(k--){
            scanf("%d %d",&xi,&yi);
            dp[xi][yi] = -1;
        }
        flag = 1;
        if(dp[1][1]==-1){
            flag = 0;
            dp[n][m] = 0;
        } 
        for(i=1;flag && i<=n;i++){
            for(j=1;j<=m;j++){

                if(i==1&&j==1){

                    continue;
                } 
                if(dp[i][j]==-1){
                    dp[i][j] = 0;
                    continue;
                } 
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%M;
            }
        }
        printf("%lld\n",dp[n][m]%M);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值