BZOJ2924 : [Poi1998]Flat broken lines

首先旋转坐标系

$x‘=x-y$

$y‘=-x-y$

则对于一个点,它下一步可以往它左上角任意一个点连线。

根据Dilworth定理,答案=这个偏序集最长反链的长度。

设f[i]为到i点为止的最长反链长度,则

f[i]=max(f[j])+1,j在i的左下角

按x坐标排序后用树状数组优化DP即可,时间复杂度$O(n\log n)$。

#include<cstdio>
#include<algorithm>
#define N 30010
int n,i,j,x,y,b[N],bit[N],f[N],ans;
struct P{int x,y;}a[N];
inline bool cmp(P a,P b){return a.x<b.x;}
inline void up(int&a,int b){if(a<b)a=b;}
inline void ins(int x,int y){for(;x<=n;x+=x&-x)up(bit[x],y);}
inline int ask(int x){int t=0;for(;x;x-=x&-x)up(t,bit[x]);return t;}
inline int lower(int x){
  int l=1,r=n,mid,t;
  while(l<=r)if(b[mid=(l+r)>>1]<=x)l=(t=mid)+1;else r=mid-1;
  return t;
}
inline void read(int&a){char c;while(!(((c=getchar())>=‘0‘)&&(c<=‘9‘)));a=c-‘0‘;while(((c=getchar())>=‘0‘)&&(c<=‘9‘))(a*=10)+=c-‘0‘;}
int main(){
  for(read(n),i=1;i<=n;i++)read(x),read(y),a[i].x=x-y,a[i].y=b[i]=-x-y;
  for(std::sort(a+1,a+n+1,cmp),std::sort(b+1,b+n+1),i=1;i<=n;i=j){
    for(j=i;j<=n&&a[j].x==a[i].x;j++)up(ans,f[j]=ask((a[j].y=lower(a[j].y))-1)+1);
    for(j=i;j<=n&&a[j].x==a[i].x;j++)ins(a[j].y,f[j]);
  }
  return printf("%d",ans),0;
}

  

时间: 2024-10-24 13:46:03

BZOJ2924 : [Poi1998]Flat broken lines的相关文章

建模美赛模板

1 \documentclass[12pt,a4paper,titlepage]{article} 2 3 \setlength{\textheight}{22.5true cm} 4 \setlength{\textwidth}{16.5true cm} \oddsidemargin -1pt 5 \evensidemargin -1pt \topmargin -1cm \setlength{\parskip}{0pt} 6 7 \usepackage{amsmath} 8 \usepacka

quarry used equipment

Basalt has a higher hardness with strength 300mp as well as the higher silicon content. And during the actual crushing and broken industry, the basalt usually cause high cost of materials broken. Therefore, for the purpose of enhancing customers' pro

Dual-voltage regulator meets USB-power needs

This Design Idea stems from the limited availability of IC voltage regulators that can meet key USB-power specs, coupled with the need for turn-on sequencing and rise-time control at each output. As always, for PC-related designs, minimum cost is a p

fed to the jaw crusher

Basalt has a higher hardness with strength 300mp as well as the higher silicon content. And during the actual crushing and broken industry, the basalt usually cause high cost of materials broken. Therefore, for the purpose of enhancing customers' pro

zabbix 监控zookeeper篇

zabbix 监控zookeeper篇 安装依赖包 yum install -y nc yum install -y zabbix-sender nc 命令 echo ruok|nc 127.0.0.1 2181 imok echo mntr|nc 127.0.0.1 2181 zk_version 3.4.6-1569965, built on 02/20/2014 09:09 GMT zk_avg_latency 0 zk_max_latency 6 zk_min_latency 0 zk_

zabbix系列zabbix3.4监控zookeeper3.4.10

监控zookeeper来自网上,大家一搜就可搜到了,只是zabbix版本和zookeeper有点出入,自行修改一下就可以了. zookeeper监控要点 系统监控 这个监控linux系统以及修改linux服务器参数即可 内存使用量 ZooKeeper应当完全运行在内存中,不能使用到SWAP.Java Heap大小不能超过可用内存. Swap使用量 使用Swap会降低ZooKeeper的性能,设置vm.swappiness = 0 网络带宽占用 如果发现ZooKeeper性能降低关注下网络带宽占用

The broken pedometer-纯暴力枚举

The broken pedometer Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description  The Broken Pedometer  The Problem A marathon runner uses a pedometer with which he is having problems. In the pedometer the symb

hust 1054 Broken Keyboard

题目描述 Bruce Force's keyboard is broken, only a few keys are still working. Bruce has figured out he can still type texts by switching the keyboard layout whenever he needs to type a letter which is currently not mapped to any of the m working keys of

poj3993Not So Flat After All(筛法素数+分解质因子)

题目链接: 啊哈哈,点我点我 题意: 题意是给出两个数字,然后有由一分解定理得,每个数可以分解成若干质因数的乘积,这样就可以在一个n维的坐标系下表示出这个点...比如给出50和24 因为24=2^3*3^1*5^0  而50=2^1*3^0*5^2那么这两个点就可以在一个3维德坐标系下表示出这两个点..24=(3,1,0)  50=(1,0,2)  那么共同拥有的维度就是3  而两个点在n维坐标系下的距离就是|3-1|+|1-0|+|0-2|=5,这样题意完全理解... 思路: 先筛出10000