题目连接:10131 - Is Bigger Smarter?

题目大意:给出n只大象的属性, 包括重量w, 智商s, 现在要求找到一个连续的序列, 要求每只大象的重量比前一只的大, 智商却要小, 输出最长值和方案, 方案不唯一的时候任意输出一种。

解题思路:DAG无定点的最长路问题, 记忆化搜索,并记录当前最有解的前驱。

#include <stdio.h>
#include <string.h>
const int N = 10005; struct State {
int w;
int s;
}tmp[N];
int n, dp[N], vis[N]; int find(int cur) {
if (dp[cur]) return dp[cur];
int a;
vis[cur] = cur;
State& now = tmp[cur];
for (int i = 0; i < n; i++) {
if (tmp[i].w < now.w && tmp[i].s > now.s) {
a = find(i);
if (dp[cur] <= a) {
dp[cur] = a;
vis[cur] = i;
}
}
}
return ++dp[cur];
} void solve() {
int Max = 0, id = 0, ans[N], cnt = 0;
for (int i = 0; i < n; i++) {
if (!dp[i]) find(i);
if (Max < dp[i]) {
Max = dp[i];
id = i;
}
} printf("%d\n", Max);
while (id != vis[id]) {
ans[cnt++] = id + 1;
id = vis[id];
}
ans[cnt++] = id + 1; for (int i = cnt - 1; i >= 0; i--)
printf("%d\n", ans[i]); } int main() {
// Init;
n = 0;
memset(tmp, 0, sizeof(tmp));
memset(vis, 0, sizeof(vis));
memset(dp, 0, sizeof(dp)); // Read;
while(scanf("%d%d", &tmp[n].w, &tmp[n].s) == 2)
n++; solve(); return 0;
}

uva 10131 Is Bigger Smarter?(DAG最长路)的更多相关文章

  1. uva 10051 Tower of Cubes(DAG最长路)

    题目连接:10051 - Tower of Cubes 题目大意:有n个正方体,从序号1~n, 对应的每个立方体的6个面分别有它的颜色(用数字给出),现在想要将立方体堆成塔,并且上面的立方体的序号要小 ...

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

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

  3. UVA 10131 - Is Bigger Smarter? (动态规划)

    Is Bigger Smarter? The Problem Some people think that the bigger an elephant is, the smarter it is. ...

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

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

  5. uva 10131 Is Bigger Smarter ? (简单dp 最长上升子序列变形 路径输出)

    题目链接 题意:有好多行,每行两个数字,代表大象的体重和智商,求大象体重越来越大,智商越来越低的最长序列,并输出. 思路:先排一下序,再按照最长上升子序列计算就行. 还有注意输入, 刚开始我是这样输入 ...

  6. 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 ...

  7. UVa 10131: Is Bigger Smarter?

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

  8. 简单Dp----最长公共子序列,DAG最长路,简单区间DP等

    /* uva 111 * 题意: * 顺序有变化的最长公共子序列: * 模板: */ #include<iostream> #include<cstdio> #include& ...

  9. NYOJ16 矩形嵌套(DAG最长路)

    矩形嵌套 紫书P262 这是有向无环图DAG(Directed Acyclic Graph)上的动态规划,是DAG最长路问题 [题目链接]NYOJ16-矩形嵌套 [题目类型]DAG上的dp & ...

随机推荐

  1. 解决screen Cannot open your terminal '/dev/pts/1'问题

    转载于:http://urchin.blog.51cto.com/4356076/1153322 问题描述: userA首先登录系统,使用screen开启了一个session,然后detach这个窗口 ...

  2. ACM第三次比赛UVA11877 The Coco-Cola Store

      Once upon a time, there is a special coco-cola store. If you return three empty bottles to the sho ...

  3. java多线程中synchronized关键字的用法

    转自:http://www.cdtarena.com/javapx/201308/9596.html 由于同一进程内的多个线程共享内存空间,在Java中,就是共享实例,当多个线程试图同时修改某个实例的 ...

  4. 彻底明白Java的IO系统

    java学习:彻底明白Java的IO系统 文章来源:互联网 一. Input和Output1. stream代表的是任何有能力产出数据的数据源,或是任何有能力接收数据的接收源.在Java的IO中,所有 ...

  5. Qt核心剖析:信息隐藏(三篇)

    http://devbean.blog.51cto.com/448512/335550 http://devbean.blog.51cto.com/448512/325581 http://devbe ...

  6. mysql字符串连接,重复等字符串函数总结

    mysql concat()函数 MySQL的concat函数可以连接一个或者多个字符串,如 select concat('10'); 输出 10 select concat('11','22','3 ...

  7. 基于visual Studio2013解决C语言竞赛题之0903文件读写

       题目

  8. OGR – Merging Multiple SHP files

    So I have 25 shapefiles with data for 25 counties, and I want to merge them all into one shapefile. ...

  9. mysql 如何修改、添加、删除表主键

    在我们使用mysql的时候,有时会遇到须要更改或者删除mysql的主键,我们能够简单的使用alter table table_name drop primary key;来完成.以下我使用数据表tab ...

  10. 四大流行的jdbc连接池之C3P0篇

    C3P0是一个开放源代码的JDBC连接池,它在lib目录中与Hibernate一起发布,包括了实现jdbc3和jdbc2扩展规范说明的Connection 和Statement 池的DataSourc ...