https://vjudge.net/contest/68966#problem/J

#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long using namespace std; const int N=,inf=0x3f3f3f;
struct edge{
int w,v;//w重量,v速度
int in;//记录位置
}e[N];
int pre[N];
void print(int x)
{
if(x!=-)print(pre[x]);
else
return ;
printf("%d\n",x+);
}
bool comp(const edge &a,const edge &b)
{
if(a.w!=b.w)return a.w<b.w;
return a.v>b.v;
}
int main()
{
int a,b,cnt=,dp[N];
while(scanf("%d%d",&a,&b)!=EOF){
e[cnt].w=a;
e[cnt].v=b;
e[cnt].in=cnt;
cnt++;
}
sort(e,e+cnt,comp);
memset(pre,-,sizeof(pre));
int ans=,index=;
for(int i=;i<cnt;i++)
{
dp[i]=;
for(int j=;j<i;j++)
{
if(e[i].w>e[j].w&&e[i].v<e[j].v)
if(dp[i]<dp[j]+)
{
dp[i]=dp[j]+;
pre[e[i].in]=e[j].in;
}
}
if(ans<dp[i])
{
ans=dp[i];
index=e[i].in;
}
}
printf("%d\n",ans);
print(index);
return ;
}

输出技巧很重要,也可以使用栈来保存后输出。

刚开始做就是没想到要排序

hdu1160dp的更多相关文章

随机推荐

  1. Java日期获取需求大全

    刚进公司,作为熟悉技术,为公司做了一个小的点餐系统的网站,其中大量用到了时间日期作为唯一标示或是显示设置.特总结了一下和大家分享. package com.lucis.ordering.Utils; ...

  2. 树链剖分-SPOJ375(QTREE)

    QTREE - Query on a tree You are given a tree (an acyclic undirected connected graph) with N nodes, a ...

  3. SQL Server中的Merge关键字 更新表数据

    简介 Merge关键字是一个神奇的DML关键字.它在SQL Server 2008被引入,它能将Insert,Update,Delete简单的并为一句.MSDN对于Merge的解释非常的短小精悍:”根 ...

  4. 去除IOS浏览器下面的工具栏

    在head标签里添加下面的元素 即可 <meta id="viewport" name="viewport" content="width=de ...

  5. 利用python的爬虫技术爬取百度贴吧的帖子

    在爬取糗事百科的段子后,我又在知乎上找了一个爬取百度贴吧帖子的实例,为了巩固提升已掌握的爬虫知识,于是我打算自己也做一个. 实现目标:1,爬取楼主所发的帖子 2,显示所爬去的楼层以及帖子题目 3,将爬 ...

  6. 【iOS】7.4 定位服务->2.1.4 定位 - 官方框架CoreLocation 案例:指南针效果

    本文并非最终版本,如果想要关注更新或更正的内容请关注文集,联系方式详见文末,如有疏忽和遗漏,欢迎指正. 本文相关目录: ================== 所属文集:[iOS]07 设备工具 === ...

  7. SocketServer模块

    在利用select实现伪并发的socket博文中我们说了: 如果要实现一个server端可以和多个客户端进行通信可以使用 1.多线程 2.多进程 3.select I/O多路复用 在那篇博文中我们介绍 ...

  8. ASP.NET Core MVC 源码学习:MVC 启动流程详解

    前言 在 上一篇 文章中,我们学习了 ASP.NET Core MVC 的路由模块,那么在本篇文章中,主要是对 ASP.NET Core MVC 启动流程的一个学习. ASP.NET Core 是新一 ...

  9. IOS开发创建开发证书及发布App应用(九)——等待审核(审核几种状态)

    以下是App应用的几种状态,如果看不到英文,建议复制到网站翻译一下就行,意思差不多能明白的 以上整套流程是在2013年写的,可能有些地方已经不太一样了,只是给大家做一下参考,毕竟再怎么改大概流程还是差 ...

  10. 老李推荐:第8章6节《MonkeyRunner源码剖析》MonkeyRunner启动运行过程-启动Monkey 4

    在获得比对设备序列号后,findAttachedDevice就会跟提供的序列号进行比对,如果吻合就返回给调用者” 代码8-6-3 AdbBackend - waitForConnection”了.而A ...