LIS(变形) HDOJ 5489 Removed Interval
2015-09-29 16:24
302 查看
题目传送门
题意:求删掉连续L长度后的LIS
分析:记rdp[i]表示以a[i]为开始的LIS长度,用nlogn的办法,二分查找-a[i]。dp[i]表示以a[i]为结尾并且删去[i-L-1, i-1]的LIS,ans = max (dp[i] + rdp[i] - 1),还要特别考虑删去最后L的长度
题意:求删掉连续L长度后的LIS
分析:记rdp[i]表示以a[i]为开始的LIS长度,用nlogn的办法,二分查找-a[i]。dp[i]表示以a[i]为结尾并且删去[i-L-1, i-1]的LIS,ans = max (dp[i] + rdp[i] - 1),还要特别考虑删去最后L的长度
/************************************************ * Author :Running_Time * Created Time :2015/9/29 星期二 15:11:29 * File Name :F.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double EPS = 1e-8; int a ; int dp , rdp ; int d ; int main(void) { int T, cas = 0; scanf ("%d", &T); while (T--) { int n, L; scanf ("%d%d", &n, &L); for (int i=1; i<=n; ++i) { scanf ("%d", &a[i]); } int ans = 0; memset (d, INF, sizeof (d)); for (int i=n; i>=1; --i) { int k = lower_bound (d+1, d+1+n, -a[i]) - d; d[k] = -a[i]; rdp[i] = k; //以a[i]为开始的LIS长度 } memset (d, INF, sizeof (d)); for (int i=1; i<=n; ++i) { if (i - L - 1 >= 1) d[lower_bound (d+1, d+1+n, a[i-L-1]) - d] = a[i-L-1]; dp[i] = lower_bound (d+1, d+1+n, a[i]) - d; //以a[i]为结尾的LIS长度 if (i > L) ans = max (ans, dp[i] + rdp[i] - 1); } if (n > L) ans = max (ans, (int) (lower_bound (d+1, d+1+n, a[n-L]) - d)); //删去最后的L长度 printf ("Case #%d: %d\n", ++cas, ans); } return 0; }
相关文章推荐
- 各种网页错误代码解释(400.404.504等)
- Oracle的基本查询
- CentOS下安装JDK1.7
- MyEclipse 8.5 注释模板设置
- js下载图片到本地
- Longest Substring Without Repeating Characters
- C#编程规范
- Spark的Shuffle机制
- js获取客户端MAC地址
- 使用node.js进行API自动化回归测试
- 日志采集之log4j2.x的使用
- UDP Sockets in C#
- VB 获取文件版本
- Python 迭代删除重复项,集合删除重复项
- eclipse/myeclipse选中编辑区域文件,Package Explorer定位文件所在项目及目录
- SEL的使用
- 关于 tomcat 集群中 session 共享的三种方法
- 【经典算法】:蛇形填数,最简单的方法了。。。
- NSUserDefaults数据保存报错:Attempt to set a non-property-list object...
- ORA-29275:部分多字节字符