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; }
查看全文
相关阅读:
在基础数据类型和在对象中 使用 == 与equals的差别
对Java中静态代理和动态代理的简单理解
MyBatis中sqlSession的创建及执行流程
Spring相关概念
AOP相关
IOC容器和Bean的配置
如何将本地项目上传到GitHub进行托管
稀疏数组
Java集合回忆
JSTL标签库
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
个人随笔之《关于好奇心》
个人随笔之《关于思考》
读书笔记之《自控力》
个人随笔之《寻找真实的自己》
个人随笔之《我有一个需要妈妈帮我实现的愿望》
Linux使用split分割大文件
VS Code添加高亮缩进功能
VS Code添加括号高亮功能
Python进阶之hasattr()、getattr()和setattr()函数的使用
前端JS定时器取消后怎样重新启动
热门文章
Python获取最近1分钟,5分钟,15分钟的时间
Python中def函数右侧有个->的含义
Lua中判断值是否在table里面
Lua中分割字符串
Nginx使用Lua模块实现WAF
MySQL_0_导入示例数据库
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Appium环境搭建(Java版本)
总结集合框架的关系
为什么 String s1="hello" String s2 = new String("hello") s1==s2 为flase
Copyright © 2011-2022 走看看