The All-purpose Zero---hdu5773(LIS变形)
Posted 西瓜不懂柠檬的酸
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The All-purpose Zero---hdu5773(LIS变形)相关的知识,希望对你有一定的参考价值。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5773
题意: 给出n个数,其中 0 可当作任何数,求能够得到的最长上升子序列(严格上升)的长度;
我们可以假设所有的零都能用上,那么结果一定包含零的个数,然后就把那些非零的数都减去它前面零的个数,然后求这些数的最长上升子序列的长度即可;
#include<iostream> #include<algorithm> #include<math.h> #include<string.h> #include<stdio.h> #include<map> #include<queue> using namespace std; #define met(a, b) memset(a, b, sizeof(a)) #define mod 1000000007 typedef long long LL; ////////////////////////////////////////////////////////////// const int INF = 0x3f3f3f3f; const double eps = 1e-8; int a[N], b[N], dp[N], n; int main() { int T, t = 1; scanf("%d", &T); while(T--) { met(a, 0); met(b, 0); scanf("%d", &n); int m = 0, cnt = 0; for(int i=0; i<n; i++) { scanf("%d", &a[i]); if(a[i] == 0) cnt ++; else b[m++] = a[i]-cnt; } met(dp, INF); for(int i=0; i<m; i++) { int pos = lower_bound(dp, dp+m, b[i]) - dp; dp[pos] = b[i]; } int ans = lower_bound(dp, dp+m, INF) - dp; printf("Case #%d: %d\\n", t++, ans+cnt); } return 0; }
以上是关于The All-purpose Zero---hdu5773(LIS变形)的主要内容,如果未能解决你的问题,请参考以下文章
HDU 5773 The All-purpose Zero(O(nlgn)求LIS)
The goddess, the bird, the bell, the temptation of the house
Read the ads,Match the titles with the
simplify the design of the hardware forming the interface between the processor and thememory system
Word2010 Error:The name in the end tag of the element must match the element type in the start tag.
Word2010 Error:The name in the end tag of the element must match the element type in the start tag.