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 ...
随机推荐
- hadoop+spark+mongodb+mysql+c#
一.前言 从20世纪90年代数字化医院概念提出到至今的20多年时间,数字化医院(Digital Hospital)在国内各大医院飞速的普及推广发展,并取得骄人成绩.不但有数字化医院管理信息系统(HIS ...
- MD5加密字符串-备用
@interface NSString (MyExtensions) - (NSString *) md5; @end @implementation NSString (MyExtensions) ...
- 更改Altium中PCB大小/精确确定板子尺寸
使用原理图生成PCB后,Altium Designer会根据原理图大小自动生成一块黑色区域,还有一个在禁止布线层的方框,还有两段标注板子大小的线.下面说一下如何更改黑色区域的大小,还有如何精确确定板子 ...
- #pragma execution_character_set的意义
就是设置执行字符集,指示char的执行字符集是UTF-8编码.如果源文件中出现中文,必须要设置为 #if _MSC_VER >= 1600 #pragma execution_ch ...
- mybatis mapper namespace
http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html#insert_update_and_delete org.apache.ibatis.excep ...
- POJ 2135 Farm Tour
题目大意:有一个无向图..农夫从1号点出发..要到达N号点..然后回到1号点..来回不能走相同的路径..问最短的距离是多少. 题解:又是不能走重复路径!基本图论算法直接扔掉上网络流.不能相同就边限1, ...
- HDU_2136——最大质因数,素数筛选法
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- HDU_2022——海选女主角
Problem Description potato老师虽然很喜欢教书,但是迫于生活压力,不得不想办法在业余时间挣点外快以养家糊口.“做什么比较挣钱呢?筛沙子没力气,看大门又不够帅...”potato ...
- Subarray Sum Closest
Question Given an integer array, find a subarray with sum closest to zero. Return the indexes of the ...
- LeeCode-String to Integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...