[Bzoj 1207] [Hnoi 2004] hit mole "DP"

Source: Internet
Author: User

Title Link: BZOJ-1207

Problem analysis

Every time the mole hit a mole must have been transferred from the last time, from the dozen J Mole can transfer to hit the first mole, calculate the distance and time difference in Manhattan to know.

Then there is a DP, using f[i] to indicate the number of moles hit by the first mole, and then f[i] can be made by f[1]. F[I-1] Transfer, similar to the longest ascending subsequence.

However, this problem can not be like the longest ascending sub-sequence optimization or tree array optimization, can only add a judge maxf[] is not large enough to exit the optimization. See Code.

Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include < Algorithm> #include <cmath>using namespace std;const int maxn = 10000 + 5;int N, ans;int F[MAXN], MAXF[MAXN], x[Ma XN], Y[MAXN], T[MAXN]; inline int Abs (int x) {return x < 0-x:x;} int main () {int fun;scanf ("%d%d", &fun, &n); Ans = 0;for (int i = 1; I <= n; ++i) {scanf ("%d%d%d", &t[i], &x[i], &y[i]); F[i] = 1;for (int j = i-1; J & Gt;= 1; --J) {if (Maxf[j] + 1 <= f[i]) break;if (F[j] + 1 > F[i] && (ABS (X[i]-x[j]) + ABS (Y[i]-y[j]) <= T[i] -t[j])) f[i] = F[j] + 1;} Maxf[i] = maxf[i-1];if (F[i] > Maxf[i]) maxf[i] = f[i];if (F[i] > ans) Ans = f[i];} printf ("%d\n", Ans); return 0;}

  

[Bzoj 1207] [Hnoi 2004] hit mole "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.