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; }
查看全文
相关阅读:
Linux 目录结构
date命令--修改linux系统时间
uniq linux下去除重复行命令
Linux查看程序端口占用情况
openfire连接登陆优化方案
hdu 4848 搜索+剪枝 2014西安邀请赛
经常使用ARM汇编指令
一维DFT
C++ lambda 表达式传递的变量默认不可变
wm命令用法及LCD显示图标大小不正常时解决的方法
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
即席查询
通过Java SE 7自带的监控服务(WatchService API)实现类似.NET FileWatcher的功能
Spring JMX之三:通知的处理及监听
单点登录相关问题总结
OAuth 的权限问题与信息隐忧
OAuth的机制原理讲解及开发流程
深入理解OAuth2.0
Linux查看程序端口占用情况
Linux下的nginx启动、重新启动
linux下IPTABLES配置详解
热门文章
diff 比较两个文件的差异
linux下passwd命令设置修改用户密码
useradd adduser linux创建用户、设置密码、修改用户、删除用户
Java中分割字符串
MySQL运行原理与基础架构
nginx限制请求之一:(ngx_http_limit_conn_module)模块
Spring JMX之二:远程访问MBean(spring通过annotation暴露MBean)
一致性哈希算法原理、避免数据热点方法及Java实现
linux文件属性详解
Linux文件类型与扩展名
Copyright © 2011-2022 走看看