题目链接

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

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

还有注意输入,

刚开始我是这样输入的   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. android中设置Animation 动画效果

    在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...

  2. git@oschina.net源代码管理使用日记

    git的优势: 1 可以创建分支: 2 版本控制是基于每一次提交的,而不需要考虑每次提交了多少个文件. 下载: 下载网址为:http://git-scm.com/download,根据您的操作系统选择 ...

  3. javascript_22_for_js性感的v

    <script type="text/javascript"> window.onload=function(){ var aDiv=document.getEleme ...

  4. 剑指offer--面试题15

    题目:打印单向链表中倒数第k个节点 以下为自己所写代码,未经过验证,只是写个思路... #include<iostream> #include<vector> #include ...

  5. 写一个函数,实现两个字符串的比较。即实现strcmp函数,s1=s2时返回0,s1!=s2时返回二者第一个不同字符的ASCII值。

    #include<stdio.h> #include<stdlib.h> int main(){ setvbuf(stdout,NULL,_IONBF,); ],s2[]; i ...

  6. jquery-validation 学习总结

    一.用前必备 项目主页:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassis ...

  7. java集合--java.util.ConcurrentModificationException异常

    ConcurrentModificationException 异常:并发修改异常,当方法检测到对象的并发修改,但不允许这种修改时,抛出此异常.一个线程对collection集合迭代,另一个线程对Co ...

  8. Opc

    http://www.tuicool.com/articles/nymUz2 http://blog.chinaunix.net/uid-20692368-id-3434001.html http:/ ...

  9. 360 chrome 国际版能够隐藏用户保存的密码

    用360 chrome 国际版一段时间了,今天发现它一个优点:取消了浏览器保存的密码明文显示! 原生的chrome和枫树都会明文显示密码,360 chrome国际版则只显示保存了密码的域名和账户名.光 ...

  10. FWT 学习总结

    我理解的FWT是在二元运算意义下的卷积 目前比较熟练掌握的集合对称差卷积 对于子集卷积和集合并卷积掌握不是很熟练(挖坑ing) 那么就先来谈一谈集合对称差卷积吧 所谓集合对称差卷积 就是h(i)=si ...