FatMouse's Speed

HDOJ-1160

注意输出长度的时候不是输出dp[n]

#include<bits/stdc++.h>
using namespace std;
const int maxn=1003;
const int INF=0X3F3F3F3F;
int w[maxn];//weight
int s[maxn];//speed
int dp[maxn];//dp[i]表示以i结尾的最长上升子序列的长度
struct node{
int weight;
int speed;
int num;
bool operator<(const node& t)const{
if(weight<t.weight&&speed>t.speed){
return true;
}else{
return false;
}
}
};
bool cmp(const node&a,const node& b){
if(a.weight==b.weight){
return a.speed>b.speed;
}else return a.weight<b.weight;
}
node mice[maxn];
int father[maxn];
int main(){
int n=0;
int i=1;
while(cin>>w[i]>>s[i]){
mice[i]=node{w[i],s[i],i};
i++;
n++;
}
memset(dp,-INF,sizeof(dp));
sort(mice+1,mice+n+1,cmp);
memset(father,-1,sizeof(father));
for(i=1;i<=n;i++){
dp[i]=1;
for(int j=1;j<i;j++){
if(mice[j]<mice[i]){
if(dp[j]+1>dp[i]){
dp[i]=dp[j]+1;
father[i]=j;
}
}
}
}
int maxs=-INF;
int maxi=0;
for(i=1;i<=n;i++){
//cout<<dp[i]<<endl;
if(dp[i]>maxs){//没有等于
maxs=dp[i];
maxi=i;
}
}
cout<<maxs<<endl;//注意这里不是直接输出dp[n],因为dp[i]表示以i结尾的子序列的最大长度,但这可能不是最终答案的最大长度。
i=maxi;
vector<int> v;
for(;i!=-1;i=father[i]){
v.push_back(mice[i].num);
//cout<<mice[i].num<<endl;
}
reverse(v.begin(),v.end());
for(int i=0;i<v.size();i++){
cout<<v[i]<<endl;
}
//system("pause");
return 0;
}

最新文章

  1. CentOS 6/7安装ffmpeg
  2. 常用查找数据结构及算法(Python实现)
  3. 利用节点更改table内容
  4. JSP前三章测试改错
  5. sqlalchemy
  6. svg技术(可缩放矢量图形)介绍
  7. Leetcode ReorderList
  8. 测试一下PHP官方的新一代PHP加速插件ZendOpcache的性能及配置
  9. 【2】开发环境的搭建,Ubuntu14.04
  10. 去掉android的屏幕上的title bar
  11. Https系列之三:让服务器同时支持http、https,基于spring boot
  12. 将 C# 枚举反序列化为 JSON 字符串 基础理论
  13. Centos运行Mysql因为内存不足进程被杀
  14. 学习pthreads,使用属性对象创建结合线程和分离线程
  15. js数据类型有哪些,js属性和方法的归属,
  16. CentOS 7 配置Maven
  17. python-异常
  18. OutputFormat输出过程的学习
  19. maven向本地库添加jar包
  20. Java零基础教程(一)环境搭建

热门文章

  1. 【noi 2.6_90】滑雪(DP)
  2. ZOJ3640-Help Me Escape 概率dp
  3. hdu1313 Round and Round We Go (大数乘法)
  4. hdu3461 Code Lock
  5. hdu1558 Segment set
  6. Codeforces Round #304 (Div. 2) C. Basketball Exercise (DP)
  7. 1.PowerShell DSC概述
  8. 1.rabbitmq 集群安装及负载均衡设置
  9. Netty(四)基于Netty 的简易版RPC
  10. 写给程序员的机器学习入门 (十一) - 对象识别 YOLO - 识别人脸位置与是否戴口罩