国防科大校赛决赛-final(镜像赛) Problem C: XueXX and Chessboard
2016-05-15 17:45
399 查看
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
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 ,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 [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 [m]%M); } return 0; }
相关文章推荐
- 国防科大校赛决赛-final(镜像赛) Problem B: XueXX and Binary
- Burp Suite使用详解
- 使用 Equinox 开发 OSGi 应用程序
- poj 1458 Common Subsequence
- 【LeetCode】95. Unique Binary Search Trees II
- Java源码学习 -- java.lang.StringBuilder,java.lang.StringBuffer,java.lang.AbstractStringBuilder
- php中include()和require()的区别
- LeetCode 60. Permutation Sequence
- 在Android Studio中进行单元测试和UI
- 【GIT】使用GIT GUI 连接到conding码库教程
- OC NSNumber NSValue
- Android中的UI
- 算法导论学习--快速排序--Quicksort
- [leetcode]347. Top K Frequent Elements
- MQTT协议 - Mosquitto安装测试
- J Arithmetic Sequence (华农第四届) 求数组中最长等差数列
- Ex2010-06 Get version number, build number
- android UI——2D绘图中应该注意的那些坑
- requirejs搭建前端框架
- Problem J: Arithmetic Sequence