#include <cstdio> int main() { int R, C; while (scanf("%d%d", &C, &R) && R) { int n, dp[101][101] = {1}; scanf("%d", &n); while (n--) { int r, c; scanf("%d%d", &c, &r); dp[r][c] = -1; } for (int r = 0; r <= R; r++) { for (int c = 0; c <= C; c++) { if (r && dp[r][c] != -1 && dp[r - 1][c] != -1) { dp[r][c] += dp[r - 1][c]; } if (c && dp[r][c] != -1 && dp[r][c - 1] != -1) { dp[r][c] += dp[r][c - 1]; } } } if (dp[R][C] <= 0) { puts("There is no path."); } else if (dp[R][C] == 1) { puts("There is one path from Little Red Riding Hood's house to her grandmother's house."); } else { printf("There are %d paths from Little Red Riding Hood's house to her grandmother's house.\n", dp[R][C]); } } return 0; }
Hello, I am a CS student from Taiwan.
I am learing English and Programming.
I'll save source code of some problems or small programs without comments in this blog.
I would recommend you not to read solution from others before you solved the problem.
(這邊專門存放沒有任何註解的小程式/OJ題目程式碼)
2013年8月28日
UVa 11067 - Little Red Riding Hood
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言