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; }
查看全文
相关阅读:
钉钉outgoing机器人小项目开发
js根据cookie判断,一天之内只弹出一次弹窗
js倒计时功能
jquery的$().each,$.each的区别
VS代码提示自动高亮
winform当前屏幕大小
动态增删改控件
datagridveiw样式
sql 语句 提取中文的首字母
按键监听及重写
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
高手速成android开源项目【导航篇】
Android UI开发【开篇导航】
数据库优化实践【MS SQL优化开篇】
JAVA面试精选【Java基础第一部分】
软件工程之系统建模篇【开卷有益】
深入理解java虚拟机【Java虚拟机类生命周期】
深入理解java虚拟机【类加载机制】
深入理解java虚拟机【Java Class类文件结构】
深入理解java虚拟机【Java虚拟机垃圾收集器】
深入理解java虚拟机【垃圾回收算法】
热门文章
深入理解java虚拟机【内存溢出实例】
深入理解java虚拟机【Java内存结构】
C++中虚析构函数作用
高手速成android开源项目【blog篇】
js不打开直接下载txt文件
php前后端分离项目跨域
thinkphp5访问路径中省略index.php方法
阿里云域名配置服务器,部署自己的网站
在本地连接阿里云服务器的mysql数据库
PHPMailer 发送邮件
Copyright © 2011-2022 走看看