Poj1925--spiderman (DP)

Source: Internet
Author: User

Topic Link: Click to open the link

The main topic: given the position of n buildings x and height y, Spider-Man from the first building to the last building to save people, to use the spider silk, every time to the same height, and in the process can not be rubbed to the ground, ask the least number of times to use the spider. (Enter in order of X)

Data is too scary, by the coordinate DP, directly enumerate the scope of the building can control, find the minimum number of times to reach the coordinates of the first. Note that it is possible to arrive at the last or the last building.

#include <cstdio> #include <cstring> #include <cmath> #include <algorithm>using namespace std; Define LL __int64#define INF 0x3f3f3f3fstruct node{    ll x, y;} P[5100]; int dp[1000010]; int main () {    int t, N, L, K, I, J;    scanf ("%d", &t);    while (t--) {        scanf ("%d", &n);        for (i = 0; i < n; i++)            scanf ("%d%d", &p[i].x, &p[i].y);        Memset (Dp,inf,sizeof (DP));        dp[p[0].x] = 0;        for (i = 1; i < n; i++) {            L = sqrt (p[i].y*p[i].y-(P[I].Y-P[0].Y) * (P[I].Y-P[0].Y));            for (j = max (p[0].x,p[i].x-l); J < p[i].x; J + +) {                if (dp[j] = = INF) continue;                k = min (p[n-1].x,2*p[i].x-j);                Dp[k] = min (dp[k],dp[j]+1);            }        }        if (dp[p[n-1].x] = = INF) dp[p[n-1].x] =-1;        printf ("%d\n", dp[p[n-1].x]);    }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Poj1925--spiderman (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.