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; }
查看全文
相关阅读:
TextBox换行C#文本框换行.net文本框换行textarea换行
日期控件 My97DatePicker WdatePicker 日期格式
Python之面向对象:继承
Python之面向对象:封装
Python之面向对象:方法
Python之面向对象:属性
Python之面向对象:面向对象基础
插入排序
冒泡排序
Python 安装MySQLdb模块遇到报错及解决方案:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
Ubuntu16.04服务器 搭建Git 服务
c++ 可变参数模板
WinForm与Javascript交互
C# 开源框架(整理)
基于Json序列化和反序列化通用的封装
C#二进制与字符串之间的相互转换
Winform实现多线程异步更新UI(进度及状态信息)
Stream、FileStream、MemoryStream的区别
延时并自动关闭MessageBox
xsl教程学习笔记
热门文章
winform中的状态栏,以及在状态栏目上显示时间
ContextMenuStrip 动态添加多级子菜单
远程桌面错误,发生身份验证错误。要求的函数不受支持
win10输入法设置
Server2012 Framework3.5安装不上
服务器上Ftp设置外网访问
天融信(NAT)地址转换端口映射配置
SQL count与distinct的结合使用
自制护眼定时锁屏
制作信函水晶报表注意事项
Copyright © 2011-2022 走看看