题目链接

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

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

还有注意输入,

刚开始我是这样输入的   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. VS2013中设置大小写的快捷键

    1.我们在定义头文件时,通常需要定义: #ifndef  _MainMenu_H_#define  _MainMenu_H_ your code... #endif 我们需要将头文件名设置为大写的: ...

  2. webview加载本地html

    //webView.loadUrl("file:///android_asset/index.html"); 加载assets目录中含有的index.html  webView.l ...

  3. aes 解密出现 java.lang.NumberFormatException: Invalid int: "ch"

    原因: 将加密/解密的seed 和 加密内容顺序放反.  decrypt(String seed, String encrypted) 附上AES解密/加密代码(android开发): package ...

  4. 1502: [NOI2005]月下柠檬树 - BZOJ

    Description Input 文件的第1行包含一个整数n和一个实数alpha,表示柠檬树的层数和月亮的光线与地面夹角(单位为弧度).第2行包含n+1个实数h0,h1,h2,…,hn,表示树离地的 ...

  5. java中的静态static关键字

    类的静态成员函数不能访问非静态的成员函数以及非静态的成员变量, 但是反过来却是成立的. 即:非静态成员函数可以访问静态成员函数和静态成员变量. 这个可以从静态成员的特点来解释,因为静态成员属于类,因此 ...

  6. SQL Server 导数据 Oracle

    1. 使用Sql Server的企业管理器导入(推荐) 优点: 可以指定导入的表. 缺点: 转成Oracle时, 对应的数据类型要一个一个手动修改   2.使用ORACLE官方提供的Sql Devel ...

  7. jsp bean标签

    jsp中存在一个奇奇怪怪的bean标签. 例如 现在在java包中定义一个类test2 package bean; public class test { private int number; pu ...

  8. hdu 4599 Dice 概率DP

    思路: 1.求f[n];dp[i]表示i个连续相同时的期望 则 dp[0]=1+dp[1]     dp[1]=1+(5dp[1]+dp[2])/6     ……     dp[i]=1+(5dp[1 ...

  9. IText 生成页脚页码

    做doc文档报表的时候可能遇到这样的需求: 每一个页面需要页码,用IText可以完成这样的需求. IText生成doc文档需要三个包:iTextAsian.jar,iText-rtf-2.1.4.ja ...

  10. 深入理解JVM—字节码执行引擎

    原文地址:http://yhjhappy234.blog.163.com/blog/static/3163283220122204355694/ 前面我们不止一次的提到,Java是一种跨平台的语言,为 ...