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; }
查看全文
相关阅读:
一周自学动态站点设计
【甘道夫】Apache Hadoop 2.5.0-cdh5.2.0 HDFS Quotas 配额控制
linux系统管理命令--系统测试工具
Atitit.异步编程 java .net php python js 对照
项目开发经常使用PHP功能
它们的定义app.config中间section节点和在执行中使用
Android 它们的定义ListView实现底部和页下拉刷新刷新的顶
vs2012连接sql2008(错误类型:Could not load file or assembly)
管理不,因为你不是说经理
java编程接口(5) ------ button和button组
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
移动终端前端开发概述
C编程的指针涛 ---第十笔记
Android Animation学习(五) ApiDemos解析:容器布局动画 LayoutTransition
Android Animation学习(四) ApiDemos解析:多属性动画
Android Animation学习(三) ApiDemos解析:XML动画文件的使用
Android Animation学习(二) ApiDemos解析:基本Animatiors使用
Android Animation学习(一) Property Animation介绍
Android Animation动画(很详细)
Android打包常见错误之Export aborted because fatal lint errors were found
【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
热门文章
android 点击下弹动画实现
Android 动画animation 深入分析
再说注解
支持向量机通俗导论(理解SVM的三层境地)
SQL注入原理解说,非常不错!
用EnableMenuItem不能使菜单变灰的原因
matlab secant method
设计模式之建造者模式
Multitasking Apps may only use background services for their intended purposes
android中listview分页载入数据
Copyright © 2011-2022 走看看