题目链接

题意:有好多行,每行两个数字,代表大象的体重和智商,求大象体重越来越大,智商越来越低的最长序列,并输出。

思路:先排一下序,再按照最长上升子序列计算就行。

还有注意输入,

刚开始我是这样输入的   cnt = 1;

while(~scanf("%d%d", &p[cnt].w, &p[cnt++].s))

结果p[1].w的值没有,为0, 所以注意在连续输入的时候不能用 cnt++;

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = +;
struct node
{
int w, s, f;
}p[maxn];
int d[maxn], h[maxn]; bool cmp(node a, node b)
{
if(a.w == b.w)
return a.s > b.s;
else
return a.w < b.w;
}
void prin(int x)
{
if(h[x] == x)
{
printf("%d\n", x);
return;
}
else
{
prin(h[x]);
printf("%d\n", x);
}
}
int main()
{
int i, j, cnt = , tmp, x, ans;
while(~scanf("%d%d", &p[cnt].w, &p[cnt].s))
{
p[cnt].f = cnt;
cnt ++;
}
sort(p+, p+cnt, cmp);
d[] = ; h[p[].f] = p[].f;
for(i = ; i < cnt; i++)
{
tmp = ; x = p[i].f;
for(j = ; j < i; j++)
{
if(p[i].w > p[j].w && p[i].s < p[j].s)
{
if(d[j] >= tmp)
{
tmp = d[j] + ;
x = p[j].f;
}
}
}
d[i] = tmp;
h[p[i].f] = x;
}
ans = ;
for(i = ; i < cnt; i++)
if(d[i] > ans)
{
ans = d[i];
x = p[i].f;
}
cout<<ans<<endl;
prin(x);
return ;
}

uva 10131 Is Bigger Smarter ? (简单dp 最长上升子序列变形 路径输出)的更多相关文章

  1. UVA 10131 Is Bigger Smarter?(DP最长上升子序列)

    Description   Question 1: Is Bigger Smarter? The Problem Some people think that the bigger an elepha ...

  2. uva 10131 Is Bigger Smarter?(DAG最长路)

    题目连接:10131 - Is Bigger Smarter? 题目大意:给出n只大象的属性, 包括重量w, 智商s, 现在要求找到一个连续的序列, 要求每只大象的重量比前一只的大, 智商却要小, 输 ...

  3. UVA 10131 - Is Bigger Smarter? (动态规划)

    Is Bigger Smarter? The Problem Some people think that the bigger an elephant is, the smarter it is. ...

  4. Uva 10131 Is Bigger Smarter? (LIS,打印路径)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=1072">链接:UVa 10131 题意: ...

  5. hdu1160简单dp最长下降子序列

    /* 简单dp,要记录顺序 解:先排序,然后是一个最长下降子序列 ,中间需记录顺序 dp[i]=Max(dp[i],dp[j]+1); */ #include<stdio.h> #incl ...

  6. 洛谷 P1020 导弹拦截(dp+最长上升子序列变形)

    传送门:Problem 1020 https://www.cnblogs.com/violet-acmer/p/9852294.html 讲解此题前,先谈谈何为最长上升子序列,以及求法: 一.相关概念 ...

  7. poj1159--Palindrome(dp:最长公共子序列变形 + 滚动数组)

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 53414   Accepted: 18449 Desc ...

  8. UVA 10131 Is Bigger Smarter?(DP)

    Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to t ...

  9. UVa 10131: Is Bigger Smarter?

    动态规划题.类似UVa103 Stacking Box,都是题目给一种判断嵌套的方法然后求最长序列.提前对数据排序可以节省一些时间开销. 我的解题代码如下: #include <iostream ...

随机推荐

  1. DB天气app冲刺二阶段第十一天(完结)

    今天最后一天冲刺了,明天就不再冲刺了..已经把所有的技术的问题还有设计的问题都弄好了吧应该说 至少目前来说是的.因为有的实现不了的或者需要耗费时间的已经果断舍弃了,然后需要完善的也都基本完善了. 现在 ...

  2. OpenWrt固件刷入后串口终端没有反应的问题

    [路由器开发板硬件固件配置] MTK双频:MT7620a + MT7612e 内存:256 MB 闪存:16 MB 固件:MTK自带SDK中的OpenWrt固件(mtksdk-openwrt-2.6. ...

  3. iOS 下拉菜单 FFDropDownMenu自定义下拉菜单样式实战-b

    Demo地址:https://github.com/chenfanfang/CollectionsOfExampleFFDropDownMenu框架地址:https://github.com/chen ...

  4. 例题-Quota 实作:

    假设这五个用户均需要进行磁盘配额限制,每个用户的配额为 2GB (hard) 以及 1.8GB (soft),该如何处理? 答: 这一题实作比较难,因为必须要包括文件系统的支持.quota 数据文件建 ...

  5. Eclipse 安装热部署JRebel

    开发环境 sts-3.7.2.RELEASE 安装步骤 1.打开应市场 2.搜索JRebel并进行下载 3.下载完成后点击JReble Configuation进入

  6. oracle 条件:1=1或1=0,动态添加条件

    看到where语句中有条件:where 1=1    和    1=2或1<>1 用途:     1=1:是为了添加条件时使用and并列其他条件时使用的(动态连接后续条件)     比如: ...

  7. [转]CentOS 5.5下FTP安装及配置

    一.FTP的安装 1.检测是否安装了FTP : [root@localhost ~]# rpm -q vsftpd vsftpd-2.0.5-16.el5_5.1 否则显示:[root@localho ...

  8. hbase操作的问题

    写了一个java程序,需要向hbase中写入大量的数据,但是这个程序执行一半就报错, 问题是,此时已经写入了很多数据. 查看jps,发现hmaster进程崩溃了. 基于以上信息,发现是在程序中,链接h ...

  9. Choosing Columns and Expressions to Index

    A key is a column or expression on which you can build an index. Follow these guidelines for choosin ...

  10. hdu 1253 胜利大逃亡(广搜,队列,三维,简单)

    题目 原来光搜是用队列的,深搜才用栈,我好白痴啊,居然搞错了 三维的基础的广搜题 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #in ...