uva 10131 Is Bigger Smarter?
来源:互联网 发布:mac如何快捷键截图 编辑:程序博客网 时间:2024/06/11 18:37
题意:给你n对数(ai,bi),在ai升序排好的情况情况下,输出最长下降子序列。
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int N=1005;struct node{ int x,y,num;}ele[N];bool cmp(const node &e1,const node &e2){ return e1.x<e2.x;}int dp[N];int main(){ int cnt=0,ans=0,pos,i; while(scanf("%d%d",&ele[cnt].x,&ele[cnt].y)!=EOF){dp[cnt]=1;ele[cnt].num=cnt+1;cnt++;} sort(ele,ele+cnt,cmp); for(i=cnt-2;i>=0;i--) { for(int j=cnt-1;j>i;j--) { if(ele[i].y>ele[j].y&&ele[i].x<ele[j].x) { dp[i]=max(dp[i],dp[j]+1); if(dp[i]>ans){ans=dp[i];pos=i;} } } } printf("%d\n",ans); while(pos<cnt) { bool flag=false; printf("%d\n",ele[pos].num); for(i=pos+1;i<cnt;i++) { if(dp[i]+1==dp[pos]&&ele[pos].y>ele[i].y) { flag=true; pos=i;break; } } if(!flag) break; }return 0;}
- UVa 10131 Is Bigger Smarter?
- UVa 10131 Is Bigger Smarter?
- UVA 10131 - Is Bigger Smarter
- uva 10131 Is Bigger Smarter?
- uva:10131 - Is Bigger Smarter?
- uva 10131 Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- Uva - 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter
- UVa 10131: Is Bigger Smarter?
- UVa:10131 Is Bigger Smarter?
- UVA - 10131 Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- 企业信息化改造该考虑什么?
- IUnknown
- JNI 类型小记
- hql中关于limit的使用
- 单片机MCS-51系列指令快速记忆法
- uva 10131 Is Bigger Smarter?
- VMALLOC_START/VMALLOC_END的值(mips架构)
- 好的
- win7下cygwin+nodeJs的安装
- 公有继承、保护继承和私有继承
- 什么是线程安全和线程不安全
- 数据结构 面试题
- 有缘无份也是美
- linux之pmap命令