这个题 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的更多相关文章

  1. HDU 1561 The more, The Better(树形背包)

    The more, The Better Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. PHP连续签到

    require "./global.php"; $act = isset($_GET['act']) ? $_GET['act'] : "error"; // ...

  2. OpenStack点滴02-WSGI

    OpenStack对外提供REST API,那么REST API是如何建立起来的呢? OpenStack用了一种叫WSGI(Web Service Gateway Interface)的东西,WSGI ...

  3. Jsonp 解决跨域问题

    话不多说直接贴代码: $.ajax({ async: false, url: 'http://****.****.com/Handler.ashx?vueId=iwNavpicS2', type: & ...

  4. iOS-OC命名规范

    IOS开发(OC)中的命名规范 正文:通过读写大量代码我有自己的一套编程思路和习惯,自认为自己的编码习惯还是不错的,代码结构也算清晰,因为我一直以来都是代码看的多写的多,但是总结的比较少,知识经常不成 ...

  5. MBProgressHUD的基本使用

    MBProgressHUD的基本使用 分类: IOS2012-10-30 11:19 12047人阅读 评论(2) 收藏 举报 和gitHub上的Demo其实差不多,就是小整理了下,当备忘,想做复杂的 ...

  6. CSS浮动属性Float详解

    什么是CSS Float? float 是 css 的定位属性.在传统的印刷布局中,文本可以按照需要围绕图片.一般把这种方式称为“文本环绕”.在网页设计中,应用了CSS的float属性的页面元素就像在 ...

  7. Java实现SOAP协议 之 HelloWorld

    Java实现SOAP协议 之 HelloWorld SOAP是把基于HTTP的WEB技术与XML的灵活性和可扩展性组合在了一起. 准备: 1. 准备一个web server.Tomcat 下载地址 h ...

  8. JVM内存堆布局图解分析

    JAVA能够实现跨平台的一个根本原因,是定义了class文件的格式标准,凡是实现该标准的JVM都能够加载并解释该class文件,据此也可以知道,为啥Java语言的执行速度比C/C++语言执行的速度要慢 ...

  9. zoj3422Go Deeper(2-sat + 二分)

    题目请戳这里 题目大意: go(int dep, int n, int m) begin output the value of dep. if dep < m and x[a[dep]] + ...

  10. 远程连接mysql

    win系统下,连接别人的mysql或者让别人链接自己的mysql: 打开命令行cmd 进入mysql: mysql -u root -p mysql>use mysql;  mysql>s ...