标签:des style io os for 文件 数据 div sp
Description
Input
Output
Sample Input
2 0 1 2 5 1 3 4 5 1 2 5 2 3 4 5 1 2
Sample Output
2 2 1 思路:我觉得挺费神的一道题,与以往的O(nlogn)LIS不一样,每次我们处理到第i个元素的时候,才去处理第i-d的数,判断是否放进队列里面#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int maxn = 100005; const int inf = 0x3f3f3f3f; int n, d; int seq[maxn], num[maxn]; int dp[maxn]; int main() { while (scanf("%d%d", &n, &d) != EOF) { for (int i = 1; i <= n; i++) scanf("%d", &seq[i]); for (int i = 0; i <= n+1; i++) num[i] = inf; memset(dp, 0, sizeof(dp)); int ans = 0; for (int i = 1; i <= n; i++) { int k = lower_bound(num, num+n, seq[i]) - num; dp[i] = k; ans = max(ans, dp[i]+1); int j = i - d; if (j > 0) { int tmp = dp[j]; num[tmp] = min(num[tmp], seq[j]); } } printf("%d\n", ans); } return 0; }
HDU - 4521 小明系列问题――小明序列 (存在间隔的LIS)
标签:des style io os for 文件 数据 div sp
原文地址:http://blog.csdn.net/u011345136/article/details/39500479