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
- csuoj-1733-XueXX and Chessboard
- csuoj-1732-XueXX and Binary
- csuoj-1731-XueXX and P-P String
- XueXX and Chessboard(中南OJ)
- 国防科大校赛决赛-final(镜像赛) Problem C: XueXX and Chessboard
- ACM L: XueXX and Binary
- CSUOJ 1302 - Walking on Chessboard 暴力BFS
- CSU1732-XueXX and Binary-简单模拟
- XueXX and P-P String(中南OJ)
- CSUOJ
- CSUOJ
- csuoj-1718- And Then There Was 5
- Chessboard
- Chessboard
- Chessboard
- 国防科大校赛决赛-final(镜像赛) Problem B: XueXX and Binary
- 国防科大校赛决赛-final(镜像赛) Problem A: XueXX and P-P String
- 暴力,组合数学(ZOJ 3779,Chessboard and Flowers)
- myeclipse修改项目名称后,部署到tomcat问题
- 10-CSS格式化排版
- java HashMap 转Object对象 工具类
- 详解依赖注入与自动装配
- myFocus实现焦点图制作
- csuoj-1733-XueXX and Chessboard
- eclipse打开选中文件(文件夹,包)的当前目录
- 怎才能进步的更快?
- runtime error怎么解决
- java学习、java入门:Java如何学?我的经验告诉你
- Spring依赖注入(DI)
- SSL/TLS Client Certs to Secure MQTT
- Android中ContentValues用法
- XML是什么,它可以做什么?——写给XML入门者