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; }
查看全文
相关阅读:
VIM配置
VSCode配置Import@路径
Sar
VIM-Fold折叠
sysctl
java8 到 java14新增的特性
Electron整合VUE
使用Markfile开发GO程序
cron 表达式
java spi
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
关于安装mySQL时报错找不到vcruntime140_1.dll的解决方案
导入openpyxl模块后运行会报错
如何在Pycharm上自动添加文件头注释
Windows下升级Python3.7.7后(原Python3.6.2版本)如何切换Python版本
python3.x安装HTMLTestRunner和使用
基于ubuntu19下python3安装tkinter GUI库
Linux19安装并切换中文输入法
修改linux下python的默认版本
解决pyCharm无法通过pip安装selenium问题
Python字符串字母大小写变换
热门文章
解决Linux系统root用户登陆失败,提示“鉴定故障”
如何解决VMware虚拟机无法连接网络的问题
PyCharm安装和使用教程(Windows系统)
必须掌握的50条Linux基础操作命令
win10系统下自由切换桌面
数据结构双向链表 DoublyLinkedList
数据结构Array
vim 十字移动图
nc命令
使用Python转换word文档到JSON
Copyright © 2011-2022 走看看