Ultraviolet A, uvaacm

Source: Internet
Author: User

Ultraviolet A, uvaacm

Question: Ultraviolet A-825 Walking on the Safe Side (dp)


A matrix of n * m is given. The starting point is 1*1 and the ending point is n * m. Some vertices in this matrix cannot pass through, it is required that the distance from the start point to the end point be the shortest, and that cannot be taken.


Solution: if the path is the shortest, do not go to the right or down of each vertex. Dp [I] [j] = dp [I] [j + 1] + dp [I + 1] [j]; when this point fails, dp [I] [j] = 0; this pitfall is input in the sample. It is not necessarily a standard input. There may be many spaces between two numbers, or there are many spaces between the last digit and the linefeed.


Code:

#include <cstdio>#include <cstring>const int N = 1005;typedef long long ll;int G[N][N];ll dp[N][N];char str[N];void handle () {int x, y;bool flag = 1;x = y = 0;//printf ("%s\n", str);for (int i = 0; i <= strlen (str); i++) {if (str[i] >= '0' && str[i] <= '9') {if (flag) x = x * 10 + str[i] - '0';elsey = y * 10 + str[i] - '0';} else {if (!flag)G[x][y] = 1;//printf ("%d %d\n", x, y);y = 0;flag = 0;}}}int main () {int t, n, m;int x, y;char ch;scanf ("%d", &t);while (t--) {scanf ("%d%d%*c", &n, &m);memset (G, 0, sizeof (G));for (int i = 1; i <= n; i++) {gets(str);handle();}for (int i = n; i >= 1; i--)for (int j = m; j >= 1; j--) {dp[i][j] = 0;if (G[i][j]) continue;if (i == n && j == m) {dp[i][j] = 1;continue;}if (i != n) dp[i][j] += dp[i + 1][j];if (j != m)dp[i][j] += dp[i][j + 1];}printf ("%lld\n", dp[1][1]);if (t)printf ("\n");}return 0;}



What is the difference between ultraviolet B and ultraviolet?

Invisible light is collectively referred to as UV
UV can be further divided into ultraviolet B and UVC Based on the wavelength.
Among them, crawlers need two types: ultraviolet B and ultraviolet.
In addition to the function of heating, ultraviolet A has the effect of sterilization and Growth Promotion (but the effect is very small ).
Ultraviolet B is a rumor that it promotes growth, but it only helps calcium deposition.
I personally think that the two types of light are of great use, but they are available in the market ....... In vain.
Because many people have studied this, the overall quality of the lamp is better. But... There are also many so-called major brands (such as climbing) that do not have UV at all.

If no lamp is needed... Use food for supplements.

What is the difference between ultraviolet B and ultraviolet?

Invisible light is collectively referred to as UV
UV can be further divided into ultraviolet B and UVC Based on the wavelength.
Among them, crawlers need two types: ultraviolet B and ultraviolet.
In addition to the function of heating, ultraviolet A has the effect of sterilization and Growth Promotion (but the effect is very small ).
Ultraviolet B is a rumor that it promotes growth, but it only helps calcium deposition.
I personally think that the two types of light are of great use, but they are available in the market ....... In vain.
Because many people have studied this, the overall quality of the lamp is better. But... There are also many so-called major brands (such as climbing) that do not have UV at all.

If no lamp is needed... Use food for supplements.

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.