题目连接: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. freemarker序列的拆分

    freemarker序列的拆分 1.简易说明 序列的拆分能够是数组.字符串.布尔值等等 2.实现源代码 <#--freemarker序列的拆分--> ${"hudjfkskhd你 ...

  2. [Unity 3D] Unity 3D 性能优化 (一)

    听到过很多用Unity 3D开发游戏的程序员抱怨引擎效率太低,资源占用太高,包括我自己在以往项目的开发中也头疼过.最近终于有了空闲,可以仔细的研究一下该如何优化Unity 3D下的游戏性能.其实国外有 ...

  3. Android Bluetooth开发

    原文地址:http://developer.android.com/guide/topics/wireless/bluetooth.html 翻译:jykenan 更新:2012.06.19 Andr ...

  4. SimpleDateFormat使用具体解释

      public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方式格式化和分析数据的详细类. 它同意格式化 ...

  5. Spring Thread Pool 线程池的应用

    Spring and Java Thread example 扫扫关注"茶爸爸"微信公众号 坚持最初的执着,从不曾有半点懈怠,为优秀而努力,为证明自己而活. Download it ...

  6. splinter python浏览器自动化操作,模拟浏览器的行为

    Splinter可以非常棒的模拟浏览器的行为,Splinter提供了丰富的API,可以获取页面的信息判断当前的行为所产生的结果   最近在研究网站自动登录的问题,涉及到需要实现浏览器自动化操作,网上有 ...

  7. em换算px

    一般浏览器默认的1em=16px,所以常用字体大小如下: 10px=0.625em 12px=0.75em 14px=0.875em 16px=1em 18px=1.125em 20px=1.25em ...

  8. 用c#开发微信(10) JSSDK 基本用法 分享接口“发送到朋友”

    微信JS-SDK是微信公众平台面向网页开发者提供的基于微信内的网页开发工具包.通过使用微信JS-SDK,网页开发者可借助微信高效地使用拍照.选图.语音.位置等手机系统的能力,同时可以直接使用微信分享. ...

  9. Linux系统中如何添加自己的库文件路径

    库文件在连接(静态库和共享库)和运行(仅限于使用共享库的程序)时被使用,其搜索路径是在系统中进行设置的.一般 Linux 系统把 /lib 和 /usr/lib 两个目录作为默认的库搜索路径,所以使用 ...

  10. 手把手教你安装QT集成开发环境(操作系统为ubuntu10.04)

    在安装QT集成开发工具包之前需要先安装build-essential和libncurses5-dev这两个开发工具和库,libncurses5-dev库是一个在Linux/Unix下广泛应用的图形函数 ...