HDU 5141
这个题 LIS + 并查集的思想 + 链式前向星
要求找s(i,j)使i j 能有最长的LIS 。。。
做法是枚举每一个j 即终点 算 起点 的可能
无力吐槽了 bc 的时候写错了一个地方 导致TLE 后来幡然醒悟了
改了就a了
+++++++++++++++++++++++++++++++++++++++++++
不想说什么了 直接上代码
+++++++++++++++++++++++++++++++++++++++++++
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <cstring>
#define CL(a,b) memset(a,b,sizeof(a))
#define ll __int64
#define TEST cout<<"TEST ***"<<endl;
#define INF 0x7ffffff0
#define MOD 1000000007
using namespace std; typedef struct node
{
int p,next;
}N;
N no[];
int head[],cv; int num[];
int fa[];
int pi[];
int so[],ct;
int n; void inithead()
{
CL(head,-);
cv=;
} void addnode(int s,int e)
{
no[cv].p=e;no[cv].next=head[s];head[s]=cv++;
} void initfa()
{
int i,j;
for(i=;i<=;i++)fa[i]=i;
} int finr(int x)
{
if(fa[x]==x)return x;
fa[x]=finr(fa[x]);
return fa[x];
} void unio(int x,int y)
{
int rx=finr(x);
int ry=finr(y);
fa[rx]=ry;
} int bin(int s,int e,int v)
{
int m=(s+e)/;
if(so[m]>=v&&so[m-]<v)return m;
if(so[m]>v)return bin(s,m,v);
return bin(m+,e,v);
} int main()
{
while(scanf("%d",&n)!=EOF)
{
int i,j,a,p,v;
initfa();
inithead();
so[]=-;ct=;
for(i=;i<=n;i++)
{
scanf("%d",&a);
num[i]=a;
if(a>so[ct])
{
ct++;
so[ct]=a;
addnode(ct,i);
pi[i]=ct;
}
else
{
p=bin(,ct,a);
so[p]=a;
addnode(p,i);
pi[i]=p;
}
if(pi[i]!=)
{
p=head[pi[i]-];
while(p!=-)
{
v=no[p].p;
if(num[v]<a)
{
unio(i,v);
break;
}
p=no[p].next;
}
}
}
ll rem=,la=,he;
i=n;
while(i>=)
{
la++;
if(pi[i]==ct)
{
he=finr(i);
rem+=la*he;
la=;
}
i--;
}
printf("%I64d\n",rem);
}
return ;
}
HDU 5141的更多相关文章
- HDU 1561 The more, The Better(树形背包)
The more, The Better Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- 设置CentOS里的Mysql开启客户端远程连接
CentOS系统安装好MySQL后,默认情况下不支持用户通过非本机连接上数据库服务器,下面是解决方法: 1.在控制台执行 mysql -u root -p mysql,系统提示输入数据库root用户的 ...
- WordPress插件制作笔记(一)---First Plugins Demo
1->add_action HOOK简单说明: http://codex.wordpress.org/Plugin_API/Action_Reference (参考网址) //在后台页脚位置加 ...
- php 学习路线 赵兴壮2014年4月28 日 加油
第一阶段 第一讲,WEB基础 1.1 网站基本知识: 1.2 网络协议介绍: 1.3 B/S与C/S结构的区别: 1.4 WEB编程.网站开发技术介绍. 第二讲,网页设计 2 ...
- 不要依赖hibernate的二级缓存
一.hibernate的二级缓存 如果开启了二级缓存,hibernate在执行任何一次查询的之后,都会把得到的结果集放到缓存中,缓存结构可以看作是一个hash table,key是数据库记录的id ...
- javaWeb防止恶意登陆或防盗链的使用
使用场景:明明引用了一个正确的图片地址,但显示出来的却是一个红叉或写有“此图片仅限于***网站用户交流沟通使用”之类的“假图片”.用嗅探软件找到了多媒体资源的真实地址用下载软件仍然不能下载.下载一些资 ...
- linux grep shell相关
http://blog.csdn.net/buutterfly/article/details/6615162 http://www.2cto.com/os/201307/224496.html ht ...
- buffer busy wait
什么是buffer busy wait? A session that reads or modifies a buffer in the SGA must first acquire the cac ...
- C++中关于函数的引用
这一块知识最常见的疑问就是: #include <iostream> #include <cstring> using namespace std; int a[50]; in ...
- 运营总监招聘-e袋洗招聘-拉勾网
运营总监招聘-e袋洗招聘-拉勾网 运营总监
- (转)Linux下Apache 限速模块安装笔记
参考文章:http://www.pcmag.com.cn/solution/net/story/200704/51003104.shtml 限线程:http://dominia.org/djao/li ...