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; }
查看全文
相关阅读:
Flask目录结构
RHSA-2019:1880-低危: curl 安全和BUG修复更新 及 RHSA-2019:1884-中危: libssh2 安全更新
ELK+Logback进行业务日志分析查看
Maven编译过程中出现的问题
Zabbix监控服务器磁盘I/O
创建readonly只读用户脚本
Zabbix监控多个JVM进程
redis命令
docker配置Nginx
docker基本命令
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
Shell脚本——for,while,until循环
Shell脚本case语句
JavaScript——DOM
Shell脚本grep命令
Shell脚本变量与判断
shell脚本作业
Shell脚本基础
Python之for循环与while循环
Python之if-else语句
python-文件操作2(读写文件的详细操作)
热门文章
python-文件的操作
python-集合
Python字符串
通用软件开发项目-目录结构规范
json反序列化与pickle的用法
pythonr-内置函数
python 变量、列表、元组、字典
linux下不同版本root密码破解
Python ---- 关于Python中的yield
Python ---- Python3的Logging模块接收命令行中传入的日志级别
Copyright © 2011-2022 走看看