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; }
查看全文
相关阅读:
4 构建Mysql+heartbeat+DRBD+LVS集群应用系统系列之Lvs为Mysql-slave做负载均衡
3 构建Mysql+heartbeat+DRBD+LVS集群应用系统系列之heartbeat的搭建
2 构建Mysql+heartbeat+DRBD+LVS集群应用系统系列之MySql的搭建
1 构建Mysql+heartbeat+DRBD+LVS集群应用系统系列之DRBD的搭建
Python
Python
Tools
DevOps
Tools
Tools
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
spark学习(1)---dataframe操作大全
计算广告(3)----广告发展趋势:合约广告、广告网络、程序化交易广告
scala学习(3)-----wordcount【sparksession】
scala学习(2)---option空值处理
Sublime Text3 BracketHighlighter高亮色彩配置
Sublime Text 3 Emmet插件安装
sublime text 3 3083 注册码
IIS7错误“Web服务器被配置为不列出此目录的内容”的解决办法
jquery实现 复选框 全选
备份对于服务器“服务器名”失败的解决办法
热门文章
VS2013中, 无法嵌入互操作类型“……”,请改用适用的接口的解决方法
.net中c#获取本机IP地址实例代码
HTML5在canvas中绘制复杂形状附效果截图
使用Office Word 2010/2013 发布文章到博客园
Docker探索系列1之docker入门安装与操作
Nginx系列5之让Nginx支持HTTP1.1
Nginx系列4之基础配置
2 NFS高可用解决方案之NFS的搭建
1 NFS高可用解决方案之DRBD+heartbeat搭建
Mysql配置项的简单优化
Copyright © 2011-2022 走看看