题意:大象真的越大越聪明吗,找出体重递增IQ递减的最长大象序列。
很明显的最长递降子序列,先把体重排序,体重一样的按iq递减排,这样就能出来了。
代码:
/*
* Author: illuz <iilluzen[at]gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: uva10131.cpp
* Create Date: 2013-09-20 22:45:08
* Descripton: dp, lds
*/
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 1001;
struct Ele {
int wei;
int iq;
int id;
} e[MAXN];
int n = 0, dp[MAXN], path[MAXN];
bool cmp(Ele a, Ele b) {
if (a.wei != b.wei)
return a.wei > b.wei;
else
return a.iq > b.iq;
}
void print(int x) {
printf("%d\n", e[x].id);
if (path[x])
print(path[x]);
else
printf("%d\n", e[0].id);
}
int main() {
while (scanf("%d%d", &e[n].wei, &e[n].iq) != EOF)
e[n].id = n + 1, path[n] = 0, dp[n++] = 1;
sort(e, e + n, cmp);
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++)
if (e[j].iq < e[i].iq && dp[j] + 1 > dp[i]) {
path[i] = j;
dp[i] = dp[j] + 1;
}
}
int ans = 0;
for (int i = 1; i < n; i++)
if (dp[ans] < dp[i])
ans = i;
printf("%d\n", dp[ans]);
print(ans);
return 0;
}
分享到:
相关推荐
The root cause for this confusion is that the term botnet size is currently poorly defined. We elucidate this issue by presenting different metrics for counting botnet membership and show that they ...
android放大镜功能源码
猫扑出品的APP,Bigger秀(破解版),免登录安装后直接可使用所有的效果,红爆你的朋友圈。
o(log n^2) is bigger b. o(log n) is bigger c. no difference 3. For a class what would happen if we call a classs constructor from with the same class!ˉs constructor . a. compilation error b. linking...
一本英文书
适用于Android和Java Final Project的Gradle 在此项目中,您将创建具有多种风格的应用程序,该应用程序使用多个库和Google Cloud Endpoints。 完成的应用程序将包含四个模块。 提供笑话的Java库,为这些笑话提供...
很好的健身小册子,lucid博客推荐,只有60页
吉蒂特·比格(Gitit Bigger) Gitit Bigger:基于Git和Markdown的Wiki,Bootstrap,ace编辑器,语法突出显示和docker部署支持。基于Git和Markdown的超棒的Wiki系统,Bootstrap,Ace编辑器等增强,支持Docker部署。...
tenforflow_convolutional_bigger_dropout,卷积
中文版见:数学名著译丛 博大精深的素数__(加)P._里本伯姆著;孙淑玲,冯克勤译.pdf
bigger-jser, 前端 JSer 装逼手册 (DEPRECATED)
资源分类:Python库 所属语言:Python 资源全名:bigger-0.2.4.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
硬盘空间计算,It may happen that a day you discover your compter disk is nearly full. And you have no clue "why". The main purpose of SpaceSniffer is to help you to dig into the content of your ...
This book will teach you how to answer these questions and more., Cracking the PM Interview is a comprehensive book about landing a product management role in a startup or bigger tech company....
Data collection at ultra high-frequency on ... Overall the difference in the coefficients is bigger between the dirty series and the clean series than among series filtered with different algorithms.
Flask-Bigger - Flask大型应用骨架
语言:English (UK) 将直播视频盒的尺寸设置为720p(HD)
BIGGER YOUR POWERPOINT-蓝橘黄粉浅绿色-飞机-PPT模板.pptx 新年春节 PPT模版
Rotated image retains size and aspect ratio of source image (destination image size is usally bigger). Supports double precision rotation angles (0..360). Supports generic bitmap structures. Specific ...