poj1836
来源:互联网 发布:搜索排名优化策划 编辑:程序博客网 时间:2024/06/05 09:41
题目大意:
给一组数字,求这组数字的最长下降子序列。
解题思路:
最长下降子序列的标准题,可以当做模板
代码如下:
#include<stdio.h>const int inf=3;int binary_search_1(double ord[],double digit,int head,int length){ int left=head,right=length; int mid; while(right!=left) { mid=(left+right)/2; if(digit==ord[mid]) return mid; else if(digit<ord[mid]) right=mid; else left=mid+1; } return left;}int binary_search_2(double ord[],double digit,int head,int length){ int left=head,right=length; int mid; while(right!=left) { mid=(left+right)/2; if(digit==ord[mid]) return mid; else if(digit>ord[mid]) right=mid; else left=mid+1; } return left;}int main(){ int n; int i,j; int max; int m; double h[1001],ord[1001]; int len_LIS,len_LDS; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { scanf("%lf",&h[i]); } max=0; for(m=1;m<=n;m++) { ord[0]=-1; len_LIS=1; for(i=1;i<=m;i++) { ord[len_LIS]=inf; j=binary_search_1(ord,h[i],0,len_LIS); if(j==len_LIS) len_LIS++; ord[j]=h[i]; } len_LIS--; ord[m]=inf; len_LDS=1; for(i=m+1;i<=n;i++) { ord[m+len_LDS]=-1; j=binary_search_2(ord,h[i],m,m+len_LDS); if(j==m+len_LDS) len_LDS++; ord[j]=h[i]; } len_LDS--; if(max<len_LIS+len_LDS) max=len_LIS+len_LDS; } printf("%d\n",n-max); } return 0;}
0 0
- poj1836
- poj1836
- poj1836
- POJ1836
- poj1836
- poj1836
- POJ1836
- [DP] poj1836
- poj1836--lis
- POJ1836--Alignment
- poj1836 Alignment
- poj1836 Alignment
- poj1836 Alignment
- POJ1836(LIS)
- poj1836 Alignment
- poj1836 Alignment
- [DP]poj1836
- Alignment poj1836
- 读 《微服务架构和实践》 笔记
- nginx根目录重定向到首页
- Java协程框架----Kilim实现机制解析
- play 集成 Ajax请求
- MYSQL相关
- poj1836
- iOS开发 - 封装一个自己的按钮
- 开发者都应该使用的10个C++11特性
- 面试如何利用最后五分钟反败为胜
- CKEditor 4 开发人员指南
- Hibernate 实体关联关系映射----总结
- Android基础组件-ContentProvider(二)
- PageRank算法
- 二分查找:Search for a Range