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; }
查看全文
相关阅读:
模板语言的作用及实例
模板语言
轮播图实例
render,render_to_redponse,locals,redirect重定向
setting中三个重要参数
python中的Celery基本使用
python中的Redis基本使用
DRF之JWT认证
DRF之过滤排序分页异常处理
DRF之权限和频率限制
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
linux下详解shell中>/dev/null 2>&1
day1:使用elasticsearch增删改查文档
day3: elasticsearch的聚合查询
day2:利用Elasticsearch来搜索数据
day0:elasticsearch了解
python生成 word 文档
python模板
八、函数定义及相关理解
七、字符串格式化(字符串拼接)
六、Python集合定义和基本操作方法
热门文章
五、阶段性练习(二)——基本数据类型
四、阶段性练习(一)——基本数据类型简单运算
三、Python基本数据类型
二、Python基础(input、变量名、条件语句、循环语句、注释)
一、Python简介及下载安装
mysql的测试题
公司主页设计
ORM创建数据库表的方式一
ORM对象关系映射
自定义simple_tag
Copyright © 2011-2022 走看看