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. C#中数组、ArrayList和List<T>三者的发展历程

    在C#中数组,ArrayList,List使我们用的最多的类型之一.他们共同的作用都是能够存储一组对象. 那么问题来了: (1)为什么要有三个一样作用的东西呢?他们都很完美吗? (2)谁先出生,又是因 ...

  2. ie、IE兼容模式,提示SCRIPT1028: 缺少标识符、字符串或数字

    旧版ie下json最后一项是不允许有逗号的 为了更好的兼容各个浏览器,json最后的逗号最好不加

  3. 转: 理解Python的With语句

    Python’s with statement provides a very convenient way of dealing with the situation where you have ...

  4. [Bootstrap]组件(二)

    按钮组 .btn-group>.btn : 一组.btn按钮包裹在.btn-group 外包元素.btn-group  {position/display/} 按钮元素.btn <div ...

  5. POJ 1384

    求猜存钱罐中至少有多少钱.容易知道金币总的重量,接着背包. #include<cstdio> #include<iostream> using namespace std; # ...

  6. .Net三维控件

    AnyCAD .Net三维建模和可视化控件为.Net 4.0开发者提供简单易用的三维建模.三维可视化和文件交换的API. 30天试用版下载: 1.  三维建模 三维建模有以下功能: 三维基本体,如点. ...

  7. JVM学习---JAVA内存

    一.JAVA运行时数据区域:JAVA中的运行时内存区域有的随着虚拟机进程的启动而存在,有的区域则是依赖用户线程的启动和结束而建立和销毁的.包括以下的几个区域. 图. JAVA虚拟机运行时数据区 1.程 ...

  8. 拥抱ARM妹纸第二季 之 第一次 点亮太阳

    上次做鱼缸LED灯时还有很多材料正好拿来用.穆等等哥- 俺去找材料. 材料列表     3W LED   x  3     散热片     x  1     恒流IC     x  1     其他零 ...

  9. Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_100_CI_AS" in the equal to operation.

    ErrorMessage Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" ...

  10. Shell 总结

    find: –name 'filenme' * ? [] ; –iname; –regex PATTERN; –user username; –group; –uid; –gid; –nouser; ...