XueXX and Chessboard(中南OJ)
来源:互联网 发布:mac steam 游戏存档 编辑:程序博客网 时间:2024/05/01 16:30
Problem C: XueXX and Chessboard
Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 155 Solved: 45
[Submit][Status][Web Board]
Description
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
35 5 01 1 03 3 12 2
Sample Output
7012
题解:
本题是DP,状态转移方程是dp[i][j]=dp[i-1][j]+dp[i][j-1],只不过要加上许多判断,最后即可求出答案,要注意输入从1开始输入,并且dp[0][1]=1,这样才能使dp[1][1]赋值为1。
最后提交上去的时候一定不要忘了取模!!!
并且,dp的题也要注意边界情况,比如这题是1 1 1 1 1 这样的话就要特殊处理!!!!
AC代码:
#include <map>#include <set>#include <list>#include <cmath>#include <queue>#include <stack>#include <bitset>#include <vector>#include <cstdio>#include <string>#include <cassert>#include <climits>#include <sstream>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int INF=-1;typedef long long ll;typedef unsigned long long ull;#define fi first#define se second#define prN printf("\n")#define SI(N) scanf("%d",&(N))#define SII(N,M) scanf("%d%d",&(N),&(M))#define SIII(N,M,K) scanf("%d%d%d",&(N),&(M),&(K))#define cle(a,val) memset(a,(val),sizeof(a))#define rep(i,b) for(int i=0;i<(b);i++)#define Rep(i,a,b) for(int i=(a);i<=(b);i++)int n,m,k;int dp[1005][1005];const int mod=1000000007;int main(){ int o; cin>>o; while(o--) { cle(dp,0); cin>>n>>m>>k; int x,y; rep(i,k) { cin>>x>>y; dp[x][y]=INF; } dp[0][1]=1; Rep(i,1,n) { Rep(j,1,m) { if(dp[i][j]==INF)continue; if (dp[i-1][j]>=0&&dp[i][j-1]>=0) { dp[i][j]+=(dp[i-1][j]+dp[i][j-1]); dp[i][j]%=mod; } if (dp[i-1][j]==INF&&dp[i][j-1]==INF) { dp[i][j]+=0; } if (dp[i-1][j]>=0&&dp[i][j-1]==INF) { dp[i][j]+=dp[i-1][j]; dp[i][j]%=mod; } if (dp[i-1][j]==INF&&dp[i][j-1]>=0) { dp[i][j]+=dp[i][j-1]; dp[i][j]%=mod; } } } if (dp[n][m]==INF) puts("0"); else printf("%d\n",dp[n][m]); } return 0;}
- XueXX and Chessboard(中南OJ)
- XueXX and P-P String(中南OJ)
- csuoj-1733-XueXX and Chessboard
- 中南oj String and Arrays
- 国防科大校赛决赛-final(镜像赛) Problem C: XueXX and Chessboard
- csuoj-1732-XueXX and Binary
- ACM L: XueXX and Binary
- csuoj-1731-XueXX and P-P String
- CSU1732-XueXX and Binary-简单模拟
- 中南大学OJ 1046 追杀
- 暴力,组合数学(ZOJ 3779,Chessboard and Flowers)
- 中南大学 oj 1330 字符识别
- Light oj 1332 - Kings in Chessboard
- 百炼OJ 1657:Distance on Chessboard
- Light oj 1010 - Knights in Chessboard
- Light OJ 1010 - Knights in Chessboard【思维】
- LIGHT OJ 1010 Knights in Chessboard
- 中南OJ 2012年8月月赛 B题 Barricade
- 飞思卡尔高级驾驶员辅助系统(ADAS)解决方案
- 学习归幷排序
- 2016百度之星资格赛 C题
- 设置ssh免登录并设置别名
- MapReduce 之 倒排索引 基本概念、设计思路和源码分析
- XueXX and Chessboard(中南OJ)
- 单例类
- Leetcode 238. Product of Array Except Self
- 实现开关按钮
- 新项目如何选择合适电源模块
- 2016"百度之星" - 资格赛(Astar Round1)Problem A B C D--java代码
- 顺序查找
- 打字练习
- c语言判断日期是否合法的函数(改进版)