uva 10131
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的更多相关文章
- Uva 10131 Is Bigger Smarter? (LIS,打印路径)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=1072">链接:UVa 10131 题意: ...
- uva 10131 Is Bigger Smarter?(DAG最长路)
题目连接:10131 - Is Bigger Smarter? 题目大意:给出n只大象的属性, 包括重量w, 智商s, 现在要求找到一个连续的序列, 要求每只大象的重量比前一只的大, 智商却要小, 输 ...
- uva 10131 Is Bigger Smarter ? (简单dp 最长上升子序列变形 路径输出)
题目链接 题意:有好多行,每行两个数字,代表大象的体重和智商,求大象体重越来越大,智商越来越低的最长序列,并输出. 思路:先排一下序,再按照最长上升子序列计算就行. 还有注意输入, 刚开始我是这样输入 ...
- UVA 10131 - Is Bigger Smarter? (动态规划)
Is Bigger Smarter? The Problem Some people think that the bigger an elephant is, the smarter it is. ...
- 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 ...
- UVa 10131: Is Bigger Smarter?
动态规划题.类似UVa103 Stacking Box,都是题目给一种判断嵌套的方法然后求最长序列.提前对数据排序可以节省一些时间开销. 我的解题代码如下: #include <iostream ...
- UVA 10131题解
第一次写动态规划的代码,整了一天,终于AC. 题目: Question 1: Is Bigger Smarter? The Problem Some people think that the big ...
- UVA 10131 Is Bigger Smarter?(DP最长上升子序列)
Description Question 1: Is Bigger Smarter? The Problem Some people think that the bigger an elepha ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
随机推荐
- javascript之Array基础篇
整理了 Array 中很基础的要掌握的知识点,希望可以帮助初学者,也希望自己以后多用多融会贯通. 创建数组 使用Array构造函数: var a=new Array();//创建一个空数组 var a ...
- 一些常用css技巧的为什么(二)我所理解的line-height
要用到的基本术语和概念: 替换元素:用作为其他内容占位符的一个元素,或说替换元素内容的部分并非由文档内容直接表示.比如img元素它由文档本身之外的一个图像来替换,比如input元素要由一个单选按钮,复 ...
- Android四大组件之一:Service(服务)
Service跟Activity也是出于统一级别的组件,且与Activity的最大区别之一主要是没有人机界面,主要是运行在程序的后台(我是这么理解的),帮助文档上说的是运行于进程的主线程中,但是服务并 ...
- 3月3日 Mark
感觉LeetCode OJ 水题较多... 不过回复基础就是这样吧.. 刚刚和Gaewah聊了下,后续可以考虑去做Topcoder的SRM或者codeforces,Mark.
- Css background缩写
例子: background:url(../images20130624/bg.png) no-repeat -1424px -5px; 官方API Value: ['background-color ...
- 《samba服务搭建》RHEL6
Samba服务不仅可以实现linux和win之间的文件共享,也可以实现linux和linux之间的共享,samba的用户只限服务端本地用户使用. 本文的环境是selinux开启的情况下配置 Samba ...
- 常用JS加密编码算法
//#region UTF8编码函数 function URLEncode(Str) { if (Str == null || Str == "") return "&q ...
- window store app 附件读取
public static async Task<bool> DisplayApplicationPicker(string folderName, string fileName) { ...
- [转]浅析AD Exchange——RTB模式
在上一篇文章中,我们了解了程序化购买,并且知道程序化购买的最基本的一种RTB的竞价模式,了解了DSP.SSP.Ad Exchange等概念,不清楚的同学可以看看上一篇文章<程序化购买>. ...
- Application,Session和Cookie
做ASP.NET,肯定会和这几个对象打交道,这些也是基础面试的常见题目,总结一下还是必要的,好在大神已经总结好了,直接参考就好了: http://www.cnblogs.com/breezeblew/ ...