题目连接: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. 2008r2 显示桌面图标

  2. PHP - 发送短信

    1.购买服务 我购买的是在百度进行推广的API服务.按照要求进行购买就好,之后获取自己的apikey. 2.将提供的代码修改后集成到项目中: <?php /** * * * 发送短信 * * * ...

  3. 谁能告诉我war包的作用及使用方法。。。。。。

    链接地址:http://zhidao.baidu.com/link?url=iliyTcmsTKb1K4gHMtWUsRIBaXglyOKIQsWwdrgvydvnaUHLe0KEoHvLVz8tLY ...

  4. opencv开源库

    opencv是开源库 在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib 为什么要CMake,这里我陈述自己的想法,作为一个刚使用opencv库的小白来说,有以下大概 ...

  5. QScriptEngine

    其实你有好多没有介绍 比如qt文字 我一直很迷惑qt的文字的长宽 qt文字的字间距 等等这些东西还有QProcess QProcess可能是qt调用c#的唯一方法了QScript要比你想象的重要,一个 ...

  6. java设计模式之——策略模式

    1.策略模式有什么好处? 策略模式的好处在于你可以动态的改变对象的行为. 2.设计原则 设计原则是把一个类中经常改变或者将来可能改变的部分提取出来,作为一个接口(c++中可以用虚类),然后在类中包含这 ...

  7. Apple严控Java太不人性化

    转自:http://www.cdtarena.com/javapx/201307/9115.html Apple为了在系统安全方面得到更好的声誉,对更容易造成系统漏洞的Java进行着严格的控制,并在自 ...

  8. WCF技术剖析之七:如何实现WCF与EnterLib PIAB、Unity之间的集成

    原文:WCF技术剖析之七:如何实现WCF与EnterLib PIAB.Unity之间的集成 在这之前,我写过深入介绍MS EnterLib PIAB的文章(参阅<MS Enterprise Li ...

  9. Redis bio

    还是一个很小的模块. bio就是background io的意思,既然要background,就要创建线程,创建几个线程呢?有几种类型的io,就创建几个线程.同一种类型的job需要排队,所以存放各自的 ...

  10. uva10791

    #include <iostream> using namespace std; int main(int argc, char *argv[]) { int j,k,m=0,flag; ...