UVA 825 Walking on the Safe Side 读入输出+DP
2014-07-11 00:05
288 查看
#include <map> #include <set> #include <list> #include <cmath> #include<cctype> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cstdio> #include <string> #include <vector> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #define LL long long #define PI 3.1415926535897932626 using namespace std; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } #define MAXN 105 int G[MAXN][MAXN],dp[MAXN][MAXN]; int W,N; int dx[]={0,1}; int dy[]={1,0}; bool judge(int x,int y){return (x>=1 && x<=W && y>=1 && y<=N); } void read() { memset(G,0,sizeof(G)); scanf("%d%d",&W,&N);getchar(); char tmp[120]; for (int i=1;i<=W;i++) { gets(tmp); // printf("%s\n",tmp); int j=0; while (isdigit(tmp[j])) j++; for (int k=j+1;k<(int)strlen(tmp);k++) { int x=0; while (isdigit(tmp[k])) { x=x*10+tmp[k]-'0'; k++; } G[i][x]=1; } } /*for (int i=1;i<=W;i++) { for (int j=1;j<=N;j++) printf("%d",G[i][j]); putchar('\n'); }*/ } int calcu(int x,int y) { if (dp[x][y]!=-1) return dp[x][y]; if (x==W && y==N) return 1; dp[x][y]=0; for (int i=0;i<2;i++) { int nx=x+dx[i]; int ny=y+dy[i]; if (!G[nx][ny] && judge(nx,ny)) dp[x][y]+=calcu(nx,ny); } return dp[x][y]; } int main() { //freopen("smaple.txt","r",stdin); int T; scanf("%d",&T); while (T) { read(); memset(dp,-1,sizeof(dp)); printf("%d\n",calcu(1,1)); if (--T) putchar('\n'); } return 0; }
相关文章推荐
- UVa 825 - Walking on the Safe Side(简单DP+数据读入)
- UVa 825 Walking on the Safe Side(简单DP)
- UVA 825 --Walking on the Safe Side+DP
- dp uva-825-Walking on the Safe Side
- uva 825 - Walking on the Safe Side(DP,输入好坑。。。)
- UVa 825 Walking on the Safe Side(DP)
- Walking on the Safe Side - UVa 825 dp
- UVa 825 Walking on the Safe Side (DP)
- UVA 题目825 Walking on the Safe Side(DP)
- uva 825 - Walking on the Safe Side(dp)
- UVA - 825 Walking on the Safe Side (dp)
- UVA 825 Walking on the Safe Side(DP)
- uva 825 - Walking on the Safe Side(dp)
- Uva-825 Walking on the Safe Side 水DP
- uva 825 Walking on the Safe Side (dp)
- uva 825 Walking on the Safe Side(dp)
- UVa 825 Walking on the Safe Side(DP)
- UVA 825 Walking on the Safe Side
- UVA - 825 Walking on the Safe Side
- UVA - 825 Walking on the Safe Side