UVa 825-walking on the Safe Side

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.