Description

 

Question 1: Is Bigger Smarter?

The Problem

Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the IQ's are decreasing.

The input will consist of data for a bunch of elephants, one elephant per line, terminated by the end-of-file. The data for a particular elephant will consist of a pair of integers: the first representing its size in kilograms and the second representing its IQ in hundredths of IQ points. Both integers are between 1 and 10000. The data will contain information for at most 1000 elephants. Two elephants may have the same weight, the same IQ, or even the same weight and IQ.

Say that the numbers on the i-th data line are W[i] and S[i]. Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing an elephant). If these nintegers are a[1]a[2],..., a[n] then it must be the case that

   W[a[1]] < W[a[2]] < ... < W[a[n]]

and

   S[a[1]] > S[a[2]] > ... > S[a[n]]

In order for the answer to be correct, n should be as large as possible. All inequalities are strict: weights must be strictly increasing, and IQs must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.

Sample Input

6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900

Sample Output

4
4
5
9
7
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn=;
int d[maxn],pre[maxn],n; struct node
{
int x,y,id;
}p[maxn]; bool mycomp(node a,node b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y>b.y;
} void printf_ans(int n,int i)
{
if(n==) return ;
int u=pre[i];
printf_ans(n-,u);
printf("%d\n",p[i].id);
} bool judge(int j,int i)
{
if(p[j].x<p[i].x&&p[j].y>p[i].y)
return true;
return false;
} int main()
{
int i,j;n=;
while(~scanf("%d%d",&p[n].x,&p[n].y))
{
p[n].id=n;n++;
}
n--;
sort(p+,p+n+,mycomp);
memset(pre,-,sizeof(pre));
memset(d,,sizeof(d));
p[].x=-;p[].y=;
for(i=;i<=n;i++)
{
for(j=;j<i;j++)
{
if(judge(j,i) && d[i]<d[j]+)
{
d[i]=d[j]+;pre[i]=j;
}
}
}
int ansm,ansi;
for(i=;i<=n;i++)
{
if(ansm<d[i])
{
ansm=d[i];ansi=i;
}
}
printf("%d\n",ansm);
printf_ans(ansm,ansi);
return ;
}

UVA 10131 Is Bigger Smarter?(DP最长上升子序列)的更多相关文章

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

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

  2. 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 ...

  3. uva 10131 Is Bigger Smarter ? (简单dp 最长上升子序列变形 路径输出)

    题目链接 题意:有好多行,每行两个数字,代表大象的体重和智商,求大象体重越来越大,智商越来越低的最长序列,并输出. 思路:先排一下序,再按照最长上升子序列计算就行. 还有注意输入, 刚开始我是这样输入 ...

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

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

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

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

  6. UVa 10131: Is Bigger Smarter?

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

  7. hdu 1025 dp 最长上升子序列

    //Accepted 4372 KB 140 ms //dp 最长上升子序列 nlogn #include <cstdio> #include <cstring> #inclu ...

  8. DP——最长上升子序列(LIS)

    DP——最长上升子序列(LIS) 基本定义: 一个序列中最长的单调递增的子序列,字符子序列指的是字符串中不一定连续但先后顺序一致的n个字符,即可以去掉字符串中的部分字符,但不可改变其前后顺序. LIS ...

  9. UVA 103 Stacking Boxes n维最长上升子序列

    题目链接:UVA - 103 题意:现有k个箱子,每个箱子可以用n维向量表示.如果一个箱子的n维向量均比另一个箱子的n维向量大,那么它们可以套接在一起,每个箱子的n维向量可以互相交换值,如箱子(2,6 ...

随机推荐

  1. js类型判别大合集

    1.typeof number,string,boolean,undefined,symbol,object,function 对象中除了函数为function,其他对象都判别为object, 缺陷: ...

  2. Angular-constructor和ngOnInit区别

    参考文档:https://blog.csdn.net/u010730126/article/details/64486997 总结:constructor做依赖注入,避免业务操作: ngOninit做 ...

  3. 标准C++(3)重载

    一.函数的重载 c++中同一作用域下能够定义同名的函数(这就叫重载),但必须满足如下要求: 1.函数的参数列表必须不同,可以使参数数量不同,也可以使参数的类型不同,甚至是参数的顺序不同. 2.函数的返 ...

  4. How to Install PhantomJS on Ubuntu 16.04

    Introduction PhantomJS is a scripted, headless browser that can be used for automating web page inte ...

  5. 使用powershell批量更新git仓库

    Get-ChildItem D:\GitHub\NetCore | ForEach-Object -Process{ cd $_.name; git pull; cd ../ }

  6. destoon去除编辑器替换图片删除原图功能,删除信息删除相关图片功能

    去除这些功能会造成大量垃圾图片,但是客户存在大量复制内容,其中图片一样,为了防止客户替换其中一个图片或者删除信息 造成其他复制信息图片丢失 去除文章模型级联图片功能. 对应模块class.php se ...

  7. mysql 编程初步

    mysql 编程 基本语法形式: 语句块模式 [begin_label] begin [statement_list] end [end_label]; label 标识符可以省略,但必须相同 流程控 ...

  8. 18.Yii2.0框架模型修改记录 和 修改点击量

    目录 修改数据 修改点击量 修改数据 上面要 use app\models\Article; //修改 //http://yii.com/?r=home/Edit public function ac ...

  9. 《零基础入门学习Python》【第一版】视频课后答案第001讲

    测试题答案: 0. Python 是什么类型的语言? Python是脚本语言 脚本语言(Scripting language)是电脑编程语言,因此也能让开发者藉以编写出让电脑听命行事的程序.以简单的方 ...

  10. vue创建路由,axios前后台交互,element-ui配置使用,django contentType组件

    vue中创建路由 每一个vue组件都有三部分组成 template:放html代码 script:放js相关 style:放css相关 vue中创建路由 1.先创建组件 Course.vue 2.ro ...