HDU 4604 Deque(LCS DP)
来源:互联网 发布:mac系统磁盘空间不足 编辑:程序博客网 时间:2024/05/10 10:51
【题意】
【AC 代码】
#include <bits/stdc++.h>using namespace std;const int inf=0x3f3f3f3f;const int maxn=100010;int n,a[maxn];int f[2][maxn],dp[maxn]; //start from i, 0 for longest non-increasing, 1 for longest non-decreasingint same[2][maxn]; //start from i, in LIS sequence, same as a[i]void solve(int *f,int *same){ memset(dp,inf,sizeof(dp)); for(int i=n; i>=1; i--){ f[i]=upper_bound(dp+1,dp+n+1,a[i])-dp; dp[f[i]]=a[i]; auto range=equal_range(dp+1,dp+n+1,a[i]); same[i]=range.second-range.first; }}int main(){ int T; scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); solve(f[0],same[0]); for(int i=1; i<=n; i++) a[i]=-a[i]; solve(f[1],same[1]); int ans=0; for(int i=1; i<=n; i++){ ans=max(ans,f[0][i]+f[1][i]-min(same[0][i],same[1][i])); } printf("%d\n",ans); }}
0 0
- HDU 4604 Deque(LCS DP)
- HDU 4604 Deque(dp、LIS)
- HDU 1080 DP LCS
- hdu 1159 dp - lcs
- HDU 1159 dp(lcs)
- hdu 4604 Deque
- hdu 4604 Deque
- HDU 4604 Deque
- HDU 4604 Deque
- HDU 4604 Deque
- HDU 4604 Deque
- hdu 4604 Deque
- hdu 4604 Deque
- HDU 4604 Deque
- hdu 1503 Advanced Fruits DP LCS
- hdu 1159 dp lcs nlogn解法
- HDU 4681 String (dp, LCS | 多校8)
- hdu 1080 Human Gene Functions(LCS&DP)
- Saving Data in SQL Databases
- UITabBar就那么点事
- 大神手册:优秀的iOS开发站点
- Eclipse 导入工程注释乱码
- phpstorm设置等号对齐
- HDU 4604 Deque(LCS DP)
- Visual SvnServer+TortoiseSvn+AnkhSVN安装设置流程笔记
- 用微信登录, 上线App Store被拒绝
- 冒泡排序思想和实现代码
- Android System Property
- Adaptive Layout
- oracle正则表达式的使用
- ApacheBench 入门知识
- 数值的扩展