hlg1186 frog across the river "DP"

Source: Internet
Author: User

Test instructions: There is a single-plank bridge on the river, and a frog wants to jump from one side of the river to the other along the plank. There were some stones on the bridge, and the frogs hated stepping on the stones. Since the length of the bridge and the distance that the frog skips all are positive integers, we can think of the point where the frog may arrive on the single plank as a series of the whole hour on the axis: 0,1,......,l (where L is the length of the bridge). A point with a coordinate of 0 represents the starting point of the bridge, and the point with the L coordinates represents the end point of the bridge. The frog jumps from the beginning of the bridge to the final direction. The distance of a single hop is any positive integer (including s,t) between S and T. When a frog jumps or jumps over a point with a coordinate of l, even if the frog has jumped out of the plank.

The topic gives the length of the bridge, the distance of the frog jumps s,t, and the position of the stone on it. Your task is to determine the minimum number of stones a frog will need to step across the river.

Analysis:

Dp[i] Represents the minimum number of stones from the I position to the end and then forward DP

Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 Const intMAXN =100005;7 Const intINF =1000000000;8 intDP[MAXN];9 intA[MAXN];Ten  One intMain () { A     intL, S, T, N; -     intD; -      while(EOF! = scanf ("%d %d%d%d", &l, &s, &t, &N)) { theMemset (A,0,sizeof(a)); -          for(inti =1; I <= N; i++) { -scanf"%d",&d); -A[D] =1; +         } -Memset (DP,0x35,sizeof(DP)); +DP[L] =0; A          for(inti = L-1; I >=0; i--) { at              for(intj = i + S; J <= i + t; J + +) { -                 if(J >=l) { -                     if(A[i]) { -Dp[i] =1; -}Else { -Dp[i] =0; in                     } -}Else { to                     if(A[i]) { +Dp[i] = min (Dp[i], dp[j] +1); -}Else { theDp[i] =min (dp[i], dp[j]); *                     } $                 }Panax Notoginseng             } -         } theprintf"%d\n", dp[0]); +     } A     return 0; the}
View Code

hlg1186 frog across the river "DP"

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.