dilworth解决的题目poj3636,poj1631
来源:互联网 发布:林湖景苑网络 编辑:程序博客网 时间:2024/06/14 00:57
//最小的链划分数问题。根据dilworth定理//为最大的反链的长度//187MS 1860K #include <iostream>#include <algorithm>using namespace std;static const int INF = ~0U>>1; static struct node{int w;int h;bool operator<(node&rs){return w<rs.w||(w==rs.w&&h>rs.h);}}Nodes[20005];static int n;static int binsearch(int B[],int num,int l,int r){int mid;while(l<r){mid = (l+r)/2;if (num<=B[mid])//下降子序列 l = mid+1;else r = mid;}return l;}//用动规求解static void DP(){int B[20010];memset(B,0,sizeof(B));//求最长下降子序列int l=0,r;int len = 0;r = len;for (int i=0;i<n;++i){l = 0;r=len;int index = binsearch(B,Nodes[i].h,l,r);B[index] = Nodes[i].h;if (len==index) len++;}printf("%d\n",len);}int main(){int T;scanf("%d",&T);while(T--){scanf("%d",&n);for (int i=0;i<n;++i){scanf("%d %d",&Nodes[i].w,&Nodes[i].h);}sort(Nodes,Nodes+n);DP();}return 0;}
//输出最长没有交叉//109MS 2072K //就是求最长上升子序列#include <iostream>#include <algorithm>using namespace std;static const int INF = ~0U>>1; static struct _node{int l,r;bool operator<(_node&b){return l<b.l||(l==b.l&&r<b.r);}}Nodes[40005];static int n;static int binsearch(int B[],int num,int l,int r){int mid;while(l<r){mid = (l+r)/2;if (num<=B[mid])//上升子序列r = mid;elsel = mid+1;}return l;}//用动规求解static void DP(){int B[40005];memset(B,0,sizeof(B));//求最长下降子序列int l=0,r;int len = 0;r = len;for (int i=0;i<n;++i){B[i] = INF;l = 0;r=len;int index = binsearch(B,Nodes[i].r,l,r);B[index] = Nodes[i].r;if (len==index)len++;}printf("%d\n",len);}int main(){int T;scanf("%d",&T);while(T--){scanf("%d",&n);for (int i=0;i<n;++i){scanf("%d",&Nodes[i].r);Nodes[i].l = i+1;}sort(Nodes,Nodes+n);DP();}return 0;}
0 0
- dilworth解决的题目poj3636,poj1631
- 【POJ3636】Nested Dolls Dilworth定理(偏序集定理二)
- poj3636
- poj1631
- poj1631
- poj1631
- poj1631
- poj1631
- poj1631
- Dilworth
- poj1631基于lower_bound的实现
- POJ1065+POJ3636
- poj1631(O(nlogn的lis解法))
- 偏序集的Dilworth定理学习 (转载)
- C解决的小小题目
- 等待解决的ACM题目
- POJ1631 - 谈解最长非降子序列的又一思路...
- NYOJ236,心急的C小加(偏序集 Dilworth 定理)
- java对AD域的密码修改!!证书导入!!!
- java 值传递与引用传递
- 用OxyPlot在WPF中演示正演磁异常的变化规律
- phpstorm webstorm 分支 和上传分支
- Python random模块
- dilworth解决的题目poj3636,poj1631
- Java通过Ldap操作AD的增删改查询
- 黑马程序员——Java基础——多线程
- CSV文件是什么?
- mysql学习笔记_函数
- 让idea中的java显示成员
- Ubuntu下安装配置和卸载Maven
- linux下出现architecture of input file `*.o' is incompatible with i386:x86-64 output的解决方法
- A20_wifi配置