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"