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 ...
随机推荐
- C程序设计语言练习题1-21
练习1-21 编写程序entab,将空格串替换为最少数量的制表符和空格,但要保持单词之间的间隔不变.假设制表符终止的位置与练习1-20的detab程序的情况相同.当使用一个制表符或者一个空格都可以打到 ...
- .NET MVC 插件化框架源码
本来想把源码整理了放github上,但最近一直忙,就直接在这里放出来了,还写得不太完整,里面有几个例子,插件上传也没写,只写了插件zip包解压,如果大家在使用中有什么疑问,可以加QQ群:1429391 ...
- 设置 cell点击 背景色
//设置 cell点击 背景色 cell.selectionStyle = UITableViewCellSelectionStyleDefault; cell.selectedBackgroundV ...
- 转:用 git 下载 uboot 源码
1. 起因: 想下载 uboot 源码,原先的方法都是下载压缩包,然后放到虚拟机上的 Ubuntu ,再解压. 在看 uboot 源码的时候,发现 v2016.01 版本的uboot中关于 board ...
- Unity3d中的Awake()、OnEnable()、Start()等默认函数的执行顺序和生命周期
Awake()在MonoBehavior创建后就立刻调用,在脚本实例的整个生命周期中,Awake函数仅执行一次:如果游戏对象(即gameObject)的初始状态为关闭状态,那么运行程序,Awake函数 ...
- 温习PYTHON语法
看WEBPY的源码结构有点晕,原来很多语法结构都忘了,继承之些. 再看A BYTE OF PYTHON.慢慢补.. number = 23 guess = int(raw_input('Enter a ...
- 【HDOJ】4544 湫湫系列故事——消灭兔子
贪心,普通贪心两层循环TLE了,然后用优先级队列维护内层. #include <iostream> #include <cstdio> #include <cstring ...
- 【转】ArrayList和LinkedList的几种循环遍历方式及性能对比分析
原文网址:http://www.trinea.cn/android/arraylist-linkedlist-loop-performance/ 主要介绍ArrayList和LinkedList这两种 ...
- FTP服务器上删除文件夹失败
很多人都知道:要删除FTP服务器上的文件夹时,必须确保文件夹下面没有其他文件,否则会删除失败! 可是,有些服务器考虑到安全等因素,通常会隐藏以点开始的文件名,例如“.test.txt”.于是,有的坏人 ...
- Linux + Apache + MySql+ Php 配置虚拟主机
win7:------------------------------------------------------------------------ NameVirtualHost *:80&l ...