UVa 825 - Walking on the Safe Side
2013-06-22 21:13
1151 查看
#include <cstring> #include <cstdio> #include <algorithm> #include <vector> #include <cctype> using namespace std; const int MAXN = 1000; int w, n; int d[MAXN][MAXN]; char buff[MAXN]; char * next(char *p) { while(isdigit(*p)) p++; if(*p == ' ') p++; return p; } void dp() { for(int i=1; i<=w; i++) { for(int j=1; j<=n; j++) { int &cur = d[i][j]; if(!cur) { if(i==1 && j==1) cur=1; else cur = d[i-1][j] + d[i][j-1]; } else { cur = 0; } } } } int main(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int T; scanf("%d", &T); while(T--) { scanf("%d%d\n", &w, &n); memset(d, 0, sizeof(d)); int t; char *p; for(int i=1; i<=w; i++) { p = buff; gets(p); sscanf(p, "%d", &t); p = next(p); while(*p) { sscanf(p, "%d", &t); d[i][t] = -1; p = next(p); } } dp(); printf("%d%s\n", d[w] , T?"\n":""); } }
相关文章推荐
- uva 825 - Walking on the Safe Side(dp)
- UVA - 825 Walking on the Safe Side (dp)
- uva 825 Walking on the Safe Side
- Walking on the Safe Side - UVa 825 dp
- UVa 825 Walking on the Safe Side(简单DP)
- UVA 825 Walking on the Safe Side
- UVa 825 Walking on the Safe Side(DP)
- uva 825 Walking on the Safe Side
- 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
- UVa 825 - Walking on the Safe Side
- uva 825 - Walking on the Safe Side
- UVA 825 Walking on the Safe Side 读入输出+DP
- UVA - 825 Walking on the Safe Side
- uva825 - Walking on the Safe Side(动规)
- UVA 825 - Walking on the Safe Side(重做)
- UVA 825 Walking on the Safe Side(DP)
- Uva-825 Walking on the Safe Side 水DP