Bzoj 3315: [Usaco2013 Nov]pogo-cow (DP)

Source: Internet
Author: User

I really want to vomit. Usaco data is weak. = = O (n^3) can be a .... The above one is O (n²), one is O (n^3)

O (n^3) procedure, first sort, DP (i, j) = max{dp (j, p)} + W (i) (t <= P <= j) represents the jump to the first point, the last point is the maximum score in J, where T is the minimum p that satisfies the condition.

When we calculate DP (i, J) (1 <= J <= i), we find that as J decreases, T is continuously decreasing, so that we only maintain H (i, J) in the DP process to represent max{DP (i, X)} (j <= x <= i), Then enumerate J in reverse order and maintain T. Time complexity O (n²)

----------------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <cstdlib>#include <cmath>#define REP (i, n) for (int i = 0; i < n; i++)#define CLR (x, C) memset (x, C, sizeof (x))using namespace std;const int MAXN = 1009;struct R {int p, v;inline void Read () {scanf ("%d%d", &p, &v);}} A[MAXN];bool Cmpl (const R &a, const R &b) {return A.P < B.P;}bool Cmpr (const R &a, const R &b) {return A.P > b.p;}int DP[MAXN][MAXN], h[maxn][maxn], n, ans = 0;void Work () {CLR (DP, 0), CLR (h, 0);h[0][0] = dp[0][0] = A[0].V;for (int i = 1; i < n; ++i) {int p = i-1;H[i][i] = dp[i][i] = A[I].V;For (int j = i-1; J >= 0; j--) {while (P && (ABS (A[I].P-A[J].P) >= abs (A[J].P-A[P-1].P) | | p > J)) p--;if (ABS (A[I].P-A[J].P) >= abs (A[J].P-A[P].P))Dp[i][j] = max (H[j][p], dp[i][j]);ans = max (ans, dp[i][j] + = A[I].V);H[i][j] = max (h[i][j + 1], dp[i][j]);}}}int main () {freopen ("test.in", "R", stdin);cin >> N;Rep (i, N) a[i]. Read ();sort (A, a + N, Cmpl);Work ();sort (A, a + N, cmpr);Work ();cout << ans << "\ n";return 0;}

-----------------------------------------------------------------------------

3315: [Usaco2013 nov]pogo-cow time limit: 3 Sec Memory Limit: MB
Submit: 185 Solved: 100
[Submit] [Status] [Discuss] Description

In an ill-conceived attempt to enhance the mobility of his prize cow Bessie, Farmer John have attached a pogo stick to each Of Bessie ' s legs. Bessie can now hop around quickly throughout the farm, but she had not yet learned what to slow down. To-help train Bessie-to-hop with greater control, Farmer John sets up a practice course for her along a straight one-dimen Sional path across his farm. At various distinct positions in the path, he places n targets on which Bessie should try-to-land (1 <= N <= 1000). Target I was located at position x (i), and was worth P (i) points if Bessie lands on it. Bessie starts at the location of all target of her choosing and are allowed to move in only one direction, hopping from tar Get to target. Each hop must cover at least as much distance as the previous hop, and must land on a target. Bessie receives credits for every target she touches (including the initial target on which she starts). Please compute the maximum number of points she can obtain.

An axis has n points, each jumping to a point will get the points of the point, and can only jump in the same direction, but the distance of each jump must not be less than the previous jump distance, the starting point choice, to obtain the maximum score.

Input

* Line 1:the integer N.

* Lines 2..1+n:line i+1 contains x (i) and P (i), each a integer in the range 0..1,000,000.

Output

* Line 1:the Maximum number of points Bessie can receive.

Sample Input6
5 6
1 1
10 5
7 6
4 8
8 10

INPUT Details:there is 6 targets. The first is at position x=5 and are worth 6 points, and so on. Sample Output25
OUTPUT Details:bessie hops from position x=4 (8 points) to position x=5 (6 points) to position x=7 (6 points) to position X=10 (5 points).

From a point with a coordinate of 4, jump to a coordinate of 5, then to a coordinate of 7 and to a coordinate of 10. HINT

Source

Silver

Bzoj 3315: [Usaco2013 Nov]pogo-cow (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.