Title: In a n*m grid, from the upper left corner to the lower right corner, there are some points can not go through, to find the shortest number of bars.
Analysis: DP, Pascal Triangle. Each point the shortest is to go to the N-bar down, M-Bar to the right road.
The number of path bars arriving at each point is the sum of the left and upper paths.
Description: Note The data entry format.
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> using namespace std; int Smap[101][101];int sums[101][101];int temp[101];int getnumber (int tem[], char str[]) {int move = 0,save = 0;while (str[ Move] {while (Str[move] < ' 0 ' | | str[move] > ' 9 ') {if (!str[move]) return save;move + +;} int value = 0;while (str[move] >= ' 0 ' && str[move] <= ' 9 ') {value *= 10;value + str[move ++]-' 0 ';} Tem[save + +] = value;} return save;} int main () {int T,n,m;char buf[1001];scanf ("%d", &t), GetChar (); while (T-) {scanf ("%d%d", &n,&m); GetChar () ; memset (SMAP, 0, sizeof (SMAP)), memset (sums, 0, sizeof (sums)); for (int i = 1; I <= N; + + i) {gets (BUF); int count = Get Number (temp, buf); for (int i = 1; i < count; + + i) smap[temp[0]][temp[i]] = 1;} SUMS[1][1] = 1;for (int i = 2; I <= N &&!smap[i][1]; + + i) sums[i][1] = 1;for (int i = 2; I <= M &&am p;!smap[1][i]; + + i) sums[1][i] = 1;for (int i = 2; I <= N; + + i) for (int j = 2; J <= M; + + j) {Sums[i][j] = sums[i-1][j]+sums[i][j-1];if (Smap[i][j]) sums[i][j] = 0;} printf ("%d\n", sums[n][m]); if (T) printf ("\ n");} return 0;}
UVa 825-walking on the Safe Side