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
随机推荐
- 20150311—html中iframe(转发)
JS实现iframe框架页面跳转和刷新 一.js方式的页面跳转 1.window.location.href方式 <script language="javascript" ...
- 8款超酷实用的CSS3 Tab菜单集合
1.CSS3华丽的Tab菜单 带小图标动画 之前我们分享过一款非常出色的CSS3 Tab菜单HTML5 SVG Tab滑块菜单,结合SVG,Tab菜单实现非常灵活.今天我们要再来分享一款基于CSS3的 ...
- input中的id和name
name在以下用途是不可替代的: 1. 表单(form)的控件名,提交的数据都用控件的name而不是id来控制.因为有许多name会同时对应多个控件,比如checkbox和radio,而id必须是全文 ...
- Microsoft Office Access 不能在追加查询中追加所有记录
有客户反映,我们的软件ACCESS数据库版本在使用时会出现"Microsoft Office Access 不能在追加查询中追加所有记录"的错误.使用客户的数据库调试软件发现错误出 ...
- Python单元测试——深入理解unittest (转)
单元测试的重要性就不多说了,可恶的是Python中 有太多的单元测试框架和工具,什么unittest, testtools, subunit, coverage, testrepository, no ...
- unity 开发总结
1.慎用线程,unity对线程的支持不是特别完善. 在一些网络通信,资源下载,解压文件,不得已要开线程操作的地方,需要进行线程回收. 2.不压缩的ab,比经过压缩的ab大了将近4倍. 在打包ngui的 ...
- 【Qt】Qt之自定义搜索框【转】
简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 简述 效果 细节分析 Coding 源码下载 效果 ...
- protobuf编译报错
在下载protobuf进行编译的时候会出现如图所示的错误 修改 C:\protobuf-2.4.1\gtest\include\gtest\internal\gtest-tuple.h(C:是我解压p ...
- php 文件上传类 实例分享
最近在研究php上传的内容,找到一个不错的php上传类,分享下. <?php /** * 文件上传类 * class: uploadFile * edit: www.jbxue.com */ c ...
- java 高精度
package BigDecimal; import java.math.BigDecimal; import java.lang.Object; public class BigDecimalTes ...