UVa 825 - Walking on the Safe Side
2012-04-30 10:24
363 查看
假期放松,做几道小题……
这道题的输入比较不同:每行输入的数的个数是不确定的,所以要使用gets和sscanf();
开始想偷懒,看了看Stainger大牛的输入也是这样,就没啥可说了,麻烦些就麻烦些;
状态转移比较明显,递推可以解决,感觉这道题与其说是dp的,不如说是用来练习输入的;
1WA,原因是最后一组输出后不要留空行(留换行);
使用了 OIer 常用的写法:把程序每一部分独立起来,确实是方便了调试(在递推时 i 没有初始化,找了很久,最后一块一块注释,发现的)。
这道题的输入比较不同:每行输入的数的个数是不确定的,所以要使用gets和sscanf();
开始想偷懒,看了看Stainger大牛的输入也是这样,就没啥可说了,麻烦些就麻烦些;
状态转移比较明显,递推可以解决,感觉这道题与其说是dp的,不如说是用来练习输入的;
1WA,原因是最后一组输出后不要留空行(留换行);
使用了 OIer 常用的写法:把程序每一部分独立起来,确实是方便了调试(在递推时 i 没有初始化,找了很久,最后一块一块注释,发现的)。
# include <stdio.h> # include <string.h> # define N 105 int row, col, f ; char t , map ; void read(void); void process(void); int main() { int T; gets(t); sscanf(t, "%d", &T); while (T--) { read(); process(); if (T != 0) putchar('\n'); } return 0; } void read(void) { int i, j, x, k; gets(t); gets(t); sscanf(t, "%d%d", &row, &col); for (i = 1; i <= row; ++i) { for (j = 1; j <= col; ++j) map[i][j] = 0; gets(t); k = 0; while (t[k] && t[k]==' ') ++k; while (t[k] && t[k]!=' ') ++k; while (t[k] && t[k]==' ') ++k; while (t[k]) { sscanf(t+k, "%d", &x); map[i][x] = 1; while (t[k] && t[k]==' ') ++k; while (t[k] && t[k]!=' ') ++k; } } } void process(void) { int i, j; f[1][1] = 1; for (j = 2; j <= col; ++j) { if (map[1][j]) f[1][j] = 0; else f[1][j] = f[1][j-1]; } for (i = 2; i <= row; ++i) { if (map[i][1]) f[i][1] = 0; else f[i][1] = f[i-1][1]; for (j = 2; j <= col; ++j) { if (map[i][j]) f[i][j] = 0; else f[i][j] = f[i-1][j] + f[i][j-1]; } } printf("%d\n", f[row][col]); }
相关文章推荐
- 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
- 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
- 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
- uva825 - 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
- UVA 825 Walking on the Safe Side