zoukankan
html css js c++ java
hdu1160最长递增子序列
//1160 #include <iostream> #include <algorithm> using namespace std; struct mouse { int id; int weight; int speed; int pos; int pre; }s[10005]; bool cmp(mouse a,mouse b) { return(a.weight<b.weight||(a.weight==b.weight&&a.speed<b.speed)); } int main() { int count=0; while(scanf("%d %d",&s[count].weight,&s[count].speed)!=EOF) { s[count].id=count+1; count++; } sort(s,s+count,cmp); /*********************************************************************************/ //最长递增子序列部分 int ans[10005]={0}; s[0].pos=1; int i,j,max=1,maxi=0; //记录每个点的序列位置 for(i=1;i<count;i++) { j=max; while(j) { if(s[i].weight>s[ans[j]].weight&&s[i].speed<s[ans[j]].speed) { s[i].pos=j+1; ans[j+1]=i; s[i].pre=ans[j]; break; } j--; } //第一个点 if(j==0) { s[i].pos=1; ans[1]=i; } //目前为止最长的点 if(s[i].pos>max) { max=s[i].pos; maxi=i; } } /* for(int cc=0;cc<count;cc++) cout<<cc<<' '<<s[cc].id<<' '<<s[cc].weight<<' '<<s[cc].speed<<' '<<s[cc].pos<<' '<<s[cc].pre<<endl; */ cout<<max<<endl; //输出最长序列 int temp[10005]; for(i=1;i<=max;i++) { temp[i]=s[maxi].id; maxi=s[maxi].pre; } for(i=max;i>0;i--) cout<<temp[i]<<endl; /*********************************************************************************/ return 0; }
查看全文
相关阅读:
第一次上机作业
第一次作业
信号
进程基础
计算机网络(第七版)谢希仁编著 第四章课后答案详解
shell脚本编程
关于linux安装软件(Ubuntu)时遇见的常见问题处理
Linux系统C语言开发环境学习
LINUX下安装中文输入法
处理《无法获得锁 /var/lib/dpkg/lock
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
C语言I博客作业07
C语言I博客作业06
C语言I博客作业05
C语言I博客作业04
C语言I博客作业03
C语言I博客作业02
C语言I博客作业01
C语言I—2019秋作业07
C语言I博客作业06
C语言I作业05
热门文章
# C语言Ⅰ博客作业02
2019秋季第一次作业
第七周作业
第七周上机练习
第六周作业
第六周上机练习
第五次作业
第四次作业
0326上机作业
第三次作业
Copyright © 2011-2022 走看看