DP 先对大象体重排序   然后寻找智力的最长升序子列  输出路径....

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define inf 0x7fffffff
using namespace std; typedef struct
{
int w,s,num;
} elem; bool cmp(elem a, elem b)
{
return a.w > b.w;
} elem tel[1010];
int q = 0;
int g[1010],d[1010],pre[1010],lu[1010];
void backtrack(int index)
{
if (pre[index] != -1)
backtrack(pre[index]);
lu[q++] = tel[index].num + 1;
}
int dd(int c)
{
d[0] = 1;
int di,m,ans = 0;
for(int i = 1; i < c; i++)
{
m = 0;
for(int j = 0; j < i; j++)
{
if(d[j] > m && tel[j].s < tel[i].s && tel[j].w > tel[i].w)
{
m = d[j];
pre[i] = j;
}
}
d[i] = m + 1;
if(d[i] > ans)
{
ans = d[i];
di = i;
}
}
printf("%d\n",ans);
backtrack(di);
for(int i = q-1; i >= 0; i--)
printf("%d\n",lu[i]);
return ans;
}
int main()
{
int n = 0;
q = 0;
memset(d, 0, sizeof(d));
memset(lu, 0, sizeof(lu));
memset(pre, -1, sizeof(pre));
while(scanf("%d%d",&tel[n].w,&tel[n].s) == 2)
{
tel[n].num = n;
n++;
}
sort(tel, tel+n, cmp);
// for(int i = 1; i <= n; i++)
// g[i] = inf;
// int ans = 0;
// int q = 0;
// for(int i = 0; i < n; i++)
// {
// int k = lower_bound(g+1, g+n+1, tel[i].s-1) - g;
// //printf("%d\n",k);
// d[i] = k;
// g[k] = tel[i].s;
// if(d[i] > ans)
// {
// ans = d[i];
// pre[q++] = i;
// //printf("%d\n",i);
// }
// }
// printf("%d\n",ans);
// for(int i = q-1; i >= 0; i--)
// printf("%d\n",tel[pre[i]].num+1);
dd(n);
return 0;
}

uva 10131的更多相关文章

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

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

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

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

  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?(DP)

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

  6. UVa 10131: Is Bigger Smarter?

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

  7. UVA 10131题解

    第一次写动态规划的代码,整了一天,终于AC. 题目: Question 1: Is Bigger Smarter? The Problem Some people think that the big ...

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

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

  9. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

随机推荐

  1. Java 类成员的初始化顺序

    Java 类成员的初始化顺序 前言:开发中碰到一个Java文件中有很多的成员变量,包括静态和非静态的,还有很多的初始化方法,很好奇这些成员的初始化顺序,在这里作个研究.   1  无继承情况下的Jav ...

  2. linux exec函数族

    1.简介 在Linux中,并不存在exec()函数,exec指的是一组函数,一共有6个,分别是: #include <unistd.h>   extern char **environ; ...

  3. C++ 11 之Lambda

    1.Lambda表达式来源于函数式编程,说白就了就是在使用的地方定义函数,有的语言叫“闭包”,如果 lambda 函数没有传回值(例如 void ),其回返类型可被完全忽略. 定义在与 lambda ...

  4. python中文json串创建与解析

    下面代码,举例说明了json如何创建和解析含有中文的json串: #coding=gbk import os import sys reload(sys) sys.setdefaultencoding ...

  5. KOBEV / KOBED

    check the highlighted. the number of execution. if too high, can be the requirement was all met. whi ...

  6. Linux常用命令操作说明(链接)

    1. Busybox下tftp命令使用详解 2. Linux中rc的含义 3. <Unix文件系统结构标准>(Filesystem Hierarchy Standard) 4. 用size ...

  7. Java中的集合类

    实线边框的是实现类,比如ArrayList,LinkedList,HashMap等 折线边框的是抽象类,比如AbstractCollection,AbstractList,AbstractMap等, ...

  8. bug汇总 (EF,Mvc,Wcf)

    此博客用于在开发过程总bug及其解决方案的记录. 1. 异常信息:  ObjectStateManager 中已存在具有同一键的对象.ObjectStateManager 无法跟踪具有相同键的多个对象 ...

  9. JavaScript 中的 replace 方法

    定义和用法 replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串. stringObject.replace(regexp/substr,replaceme ...

  10. 关于华为C8812救砖教程

    问题:华为C8812刷机后,开机显示:---------------------------------------------------------------- Image signature ...