csuoj-1733-XueXX and Chessboard

来源:互联网 发布:php app接口开发实例 编辑:程序博客网 时间:2024/05/22 10:39

Description

XueXX is a clever boy. And he always likes to do something withchessboard. 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 by1,000,000,007.

Input

The first line of input contains the number of test casesT. The descriptions of the test cases follow: The first line of each test case contains three integersn, 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 by1,000,000,007).

Sample Input

35 5 01 1 03 3 12 2

Sample Output

7012


简单dp

#include <cstdio>#include <cstring>using namespace std;typedef long long ll;const int mod = 1000000007;const int maxn = 1005;ll dp[maxn][maxn];int n, m, cnt;bool vis[maxn][maxn]; int main(){    int T;    scanf("%d", &T);    while (T--){        scanf("%d%d%d", &n, &m, &cnt);        int x, y;        memset(vis, false, sizeof(vis));        memset(dp, 0, sizeof(dp));        while (cnt--){            scanf("%d%d", &x, &y);            vis[x][y] = true;        }        dp[1][1] = 1;        for (int i=2; i<maxn; ++i){            if (!vis[1][i-1])                dp[1][i] = dp[1][i-1];            if (!vis[i-1][1])                dp[i][1] = dp[i-1][1];        }        for (int i=2; i<maxn; ++i)        for (int j=2; j<maxn; ++j){            if (!vis[i][j-1]){                dp[i][j] += dp[i][j-1];                dp[i][j] %= mod;            }            if (!vis[i-1][j]){                dp[i][j] += dp[i-1][j];                dp[i][j] %= mod;            }        }        printf("%lld\n", dp[n][m]);    }    return 0;}


0 0
原创粉丝点击