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; }
查看全文
相关阅读:
域控制器的常规卸载,Active Directory系列之十三
理解域信任关系,Active Directory系列之十六
什么是站点,Active Directory系列之十一
域控制器的强制卸载,Active Directory系列之十四
详解操作主机角色,Active Directory系列之九
【转】MapControl和PageLayoutControl的同步
AE的一些接口小记
【转】centos linux 上flv/swf视频服务器架设
lnmp配置超精简免费flv流媒体服务器笔记
Flash game 遊戲修改 Cheat Engine 5.4 使用教學
原文地址:https://www.cnblogs.com/windmissing/p/2559896.html
最新文章
基于Atom协议的数据接入规范
哈希(Hash)与加密(Encrypt)的基本原理、区别及工程应用
利用java控制window服务
hash算法的介绍 【清晰易懂】
哈希(Hash)与加密(Encrypt)的基本原理、区别及工程应用
vbs生成域账号
js编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数求1/1+1/3+...+1/n...
js计算两个数字的最大公约数
js利用递归求斐波那契数列兔子繁殖问题
js递归法求阶乘
热门文章
大学所做项目总结
设计模式读书笔记装饰者模式
设计模式读书笔记抽象工厂模式
设计模式读书笔记工厂方法模式
设计模式读书笔记简单工厂模式
实战详解域信任关系,Active Directory系列之十七
域控制器的终极卸载,Active Directory系列之十五
创建Win2003域和Win2008域之间的信任关系,Active Directory系列之十八
实战Active Directory站点部署与管理,Active Directory系列之十二
实战操作主机角色转移,Active Directory系列之十
Copyright © 2011-2022 走看看