hdu5489 树状数组+dp
2015-10-06 21:49:54
这题说的是个给了一个数组,然后删除任意起点的一个连续的L个数,然后求最长递增子序列《是递增,不是非递减》,用一个树状数组维护一下就ok了
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn=;
int A[maxn],B[maxn];
int dp[maxn][];
int NUM[maxn][],N;
int lowbit(int x)
{
return x&(-x);
}
void add(int loc, int v,int op)
{
while(loc<=N)
{
NUM[loc][op]=max(v,NUM[loc][op]);
loc+=lowbit(loc);
}
}
int sum(int loc, int op)
{
int ans=;
while(loc>)
{
ans=max(ans,NUM[loc][op]);
loc-=lowbit(loc);
}
return ans;
}
int main()
{
int cas;
scanf("%d",&cas);
for(int cc=; cc<=cas; cc++)
{
int n,L;
scanf("%d%d",&n,&L); int id=;
for(int i=; i<n; i++)
{
scanf("%d",&A[i]);
B[i]=A[i];
if(A[i]<A[id])id=i;
}
if(L==n){
printf("Case #%d: %d\n",cc,);continue;
}
B[n]=A[id]-;
sort(B,B+(n+));
N=unique(B,B+(n+))-B;
memset(NUM,,sizeof(NUM));
for(int i=; i<n; i++){
A[i]=lower_bound(B,B+N,A[i])-B+;
}
int ans=;
for(int i=; i<n; i++)
{
dp[i][]=dp[i][]=;
int Loc=A[i];
int AA=sum(Loc-,);
dp[i][]=AA+;
AA=sum(Loc-,);
dp[i][]=max(dp[i][],AA+);
if(n-L>i){
dp[i][]=sum(Loc-,)+;
}
if(i-L>=){
add(A[i-L],dp[i-L][],);
}
if(i>=L){
add(A[i],dp[i][],);
}
if(n-L>i){
add(A[i],dp[i][],);
}
ans=max(max(dp[i][],dp[i][]),ans);
}
printf("Case #%d: %d\n",cc,ans);
}
return ;
}
hdu5489 树状数组+dp的更多相关文章
- codeforces 597C (树状数组+DP)
题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k ...
- hdu 4622 Reincarnation trie树+树状数组/dp
题意:给你一个字符串和m个询问,问你l,r这个区间内出现过多少字串. 连接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 网上也有用后缀数组搞得. 思路 ...
- Codeforces 597C. Subsequences (树状数组+dp)
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...
- HDU2227Find the nondecreasing subsequences(树状数组+DP)
题目大意就是说帮你给出一个序列a,让你求出它的非递减序列有多少个. 设dp[i]表示以a[i]结尾的非递减子序列的个数,由题意我们可以写出状态转移方程: dp[i] = sum{dp[j] | 1&l ...
- CodeForces - 314C Sereja and Subsequences (树状数组+dp)
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...
- HDU 6348 序列计数 (树状数组 + DP)
序列计数 Time Limit: 4500/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- [Codeforces261D]Maxim and Increasing Subsequence——树状数组+DP
题目链接: Codeforces261D 题目大意:$k$次询问,每次给出一个长度为$n$的序列$b$及$b$中的最大值$maxb$,构造出序列$a$为$t$个序列$b$连接而成,求$a$的最长上升子 ...
- 【XSY2727】Remove Dilworth定理 堆 树状数组 DP
题目描述 一个二维平面上有\(n\)个梯形,满足: 所有梯形的下底边在直线\(y=0\)上. 所有梯形的上底边在直线\(y=1\)上. 没有两个点的坐标相同. 你一次可以选择任意多个梯形,必须满足这些 ...
- hdu5125 树状数组+dp
hdu5125 他说的是n个人每个人都有两个气球a,b,气球各自都有相应的体积,现在让他们按照序号排列好来,对他们的a气球体积值计算最长上升子序列,对于这整个排列来说有m次机会让你将a气球替换成b气 ...
随机推荐
- STS maven build 访问 jsp页面报错
STS 版本:spring-tool-suite-3.8.1.RELEASE-e4.6-win32-x86_64 maven版本:apache-maven-3.3.9 报错信息如图(图片解决方案来源博 ...
- LeetCode 896 Monotonic Array 解题报告
题目要求 An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is ...
- Spring 测试
1. pom.xml ==> Depency <!-- Test --> <dependency> <groupId>junit</groupId> ...
- js 正则判断字符串下划线的长度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JQPRINT-不错的jquery打印插件
1.首先引用Jquery和jqprint-0.3.js(依赖于Jquery的) <script language="javascript" src="jquery- ...
- 7620N路由器刷openwrt系统并配置***
之前一直用goAgent***,主要用gmail.逛逛twitter.youtube.维基百科.加速stackoverflow等等.但goAgent只能PC使用,手机.iPad都不能用,直到我拿到了一 ...
- MySQL 5.5 服务器变量详解(二)
innodb_adaptive_flushing={ON|OFF} 设定是否允许MySQL服务器根据工作负载动态调整刷写InnoDB buffer pool中的脏页的速率.动态调整刷写速率的目的在于避 ...
- pt-table-checksum 使用实践
在另外部署的机器上执行: pt-table-checksum h='192.168.122.47',u='root',p='cc.123',P=3306 -d cat --nocheck-r ...
- HBuilder 自动整理代码格式快捷键设置
工具 ->选项
- [py]环境变量的获取os.environ.get和设置
$ export name='maotai' $ python >>> import os >>> os.environ.get('name', "&qu ...