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
随机推荐
- C#中多线程的简单应用
下面是C#中使用多线程的一个简单用法介绍: //主线程: Thread thread = new Thread(new ThreadStart(ReadExportData));//创建分支线程thr ...
- OpenStack 加入新的节点,创建虚拟机失败的问题
最开始做OpenStack的时候,由于只是为了部署测试用,因此将所有的部分都装在一台单网卡的机器上,费了九牛二虎之力终于部署成功,其中最主要的两块问题出现在以下两个方面: 1:nova.neutron ...
- GForms展现服务云开发平台
GForms完全基于开放标准,使用XForms作为面向服务的架构简单易用的前端,帮助用户跨多个行业加速数据整合.GForms提供可视化设计器,实现展现服务开发中数据与模型完全分离,加快开发速度快速投入 ...
- tslib 移植问题与解决方法
问题一.执行脚本.提示出错,错误有"cann't exec aclocal" ,错误提示最多的是关于aclocal的问题,查资料显示这个文件是automake必备一个文件,好吧,那 ...
- CSS Sprite 雪碧图制作
CSS Sprite 雪碧图,简单来说就是: 为了提高网页的性能,减少加载次数,将一些不会经常随网站内容变化的小图标,集中放在一张大图上,将该图应作为background-image 嵌入页面中,在需 ...
- DB2&&oracle-培训内容
DB2 1 Data Sharing架构,高可用 2 DB2的对象主要有以下几类:database,storage group, Tablspace, indexspace, table,index ...
- 设置textview显示框内容不可编辑不可选择。
f1textview.allowsEditingTextAttributes=NO;////////////设置不可编辑不能用这个,得用下面的一个 textView.editable=NO;//设置可 ...
- .NET中变量的类型问题
1.JAVA和C# Byte的不同. java里一个byte取值范围是-128~127, 而C#里一个byte是0~255. 首位不同. 但是底层I/O存储的数据是一样的, 比如, 十进制的100, ...
- 【Qt】QSettings介绍【转】
简介 QSettings类提供了持久的跨平台应用程序设置. 用户通常期望应用程序记住它的设置(窗口大小.位置等)所有会话.这些信息通常存储在Windows系统注册表,OS X和iOS的属性列表文件中. ...
- Reveal 配置与使用
http://www.th7.cn/Program/IOS/201608/939231.shtml http://www.jianshu.com/p/abac941c2e8e 这个比较好.http:/ ...