P1052 Across the river

Source: Internet
Author: User

It was simple and difficult afterwards. It was simple and difficult afterwards.

This problem if this \ (l\) is a big water problem, but the data is a bit difficult.

Obviously we can discretization, the specific operation is the distance between the point of indentation and points. What I'm using here is a 2520-indent.

\[2520=LCM (,..., 10) and 1 \leq s \leq T \leq 10\]

So we have a direct% of the distance between the two adjacent points 2520.

But pay attention to the handling of the \ (s=t\) situation. I refer to one of the methods in the solution.

The last stone after the end of the indentation is obviously not the end point, we have to get it out of the real end.

We look for the minimum value of the answer in the t\ length interval headed by the last stone, and we can transfer the state from any of these elements as the end point, and we take the smallest answer, which is optimal.

Code:

#include <cstdio> #include <cstring> #include <algorithm>const int maxn = 500005;int L, s, T, M;int dp[    Maxn];int stone[105], newstone[105], Newl;bool havestone[maxn];void solve () {int now = 0, ans = 0;            for (int i = 1; I <= m; i++) {if ([Stone[i]-now)% s = = 0) {now = Stone[i];        ans++;    } else if (now + (Stone[i] – now)% s <= l) today = Now + (Stone[i] – now)% s; } printf ("%d\n", ans);}    int main () {scanf ("%d%d%d%d", &l, &s, &t, &m);    for (int i = 1; I <= m; i++) scanf ("%d", &stone[i]);    Std::sort (stone + 1, stone + M + 1);    Memset (DP, 0x3f, sizeof DP);        for (int i = 1; I <= m; i++) {newstone[i] = Newstone[i-1] + ((Stone[i]-stone[i-1])% 2520);    Havestone[newstone[i]] = true;    } Dp[0] = 0;  for (int i = 1; I <= newstone[m] + t, i++) {for (int j = t; J >= S; j--) {if (I-j >= 0) {DP[i] = Std::min (Dp[i], dp[i-j] + (int) (havestone[i]));    }}} int ans = 0x3f3f3f3f;    for (int i = newstone[m]; I <= newstone[m] + t; i++) ans = std::min (ans, dp[i]);    printf ("%d\n", ans); return 0;}

P1052 across the river

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.