UVa 10131 Is Bigger Smarter? (DP&LIS)
来源:互联网 发布:ui用什么软件 编辑:程序博客网 时间:2024/06/05 01:57
10131 - Is Bigger Smarter?
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=1072
Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the IQ's are decreasing.
The input will consist of data for a bunch of elephants, one elephant per line, terminated by the end-of-file. The data for a particular elephant will consist of a pair of integers: the first representing its size in kilograms and the second representing its IQ in hundredths of IQ points. Both integers are between 1 and 10000. The data will contain information for at most 1000 elephants. Two elephants may have the same weight, the same IQ, or even the same weight and IQ.
Say that the numbers on the i-th data line are W[i] and S[i]. Your program should output a sequence of lines of data; the first line should contain a numbern; the remaining n lines should each contain a single positive integer (each one representing an elephant). If thesen integers are a[1], a[2],..., a[n] then it must be the case that
W[a[1]] < W[a[2]] < ... < W[a[n]]and
S[a[1]] > S[a[2]] > ... > S[a[n]]In order for the answer to be correct, n should be as large as possible. All inequalities are strict: weights must be strictly increasing, and IQs must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
Sample Input
6008 13006000 2100500 20001000 40001100 30006000 20008000 14006000 12002000 1900
Sample Output
44597
怎么排序?可以按照first和second均从大到小排,first优先。
完整代码:
/*0.016s*/#include<bits/stdc++.h>using namespace std;const int MAXN = 1001;struct node{int wei, iq, id;bool operator < (const node& a) const{return wei > a.wei || wei == a.wei && iq > a.iq;///iq也这么排是为了方便后面求dp时不用判断wei是否相等~}} e[MAXN];int dp[MAXN], path[MAXN];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(){int n = 0, ans = 0, i, j;while (~scanf("%d%d", &e[n].wei, &e[n].iq))e[n].id = n + 1, dp[n++] = 1;sort(e, e + n);for (i = 1; i < n; ++i)for (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;for (i = 1; i < n; ++i)if (dp[ans] < dp[i])ans = i;printf("%d\n", dp[ans]);print(ans);return 0;}
- UVa 10131 Is Bigger Smarter? (DP&LIS)
- 【DP】UVA 10131 Is Bigger Smarter? LIS
- UVA 10131 Is Bigger Smarter? DP
- UVA 10131 Is Bigger Smarter ? DP ,Commencel
- UVA 10131 Is Bigger Smarter? (DP)
- Is Bigger Smarter? - UVa 10131 dp
- UVA 10131 Is Bigger Smarter?(DP)
- Uva 10131-Is Bigger Smarter?(DP)
- uva--10131Is Bigger Smarter? +dp
- UVA - 10131 - Is Bigger Smarter? (动态规划,LIS)
- Uva 10131 Is Bigger Smarter? (LIS,打印路径)
- UVa 10131 Is Bigger Smarter?
- UVa 10131 Is Bigger Smarter?
- UVA 10131 - Is Bigger Smarter
- uva 10131 Is Bigger Smarter?
- uva:10131 - Is Bigger Smarter?
- uva 10131 Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter?
- Android Sdk更新速度慢解决(转载)
- 一个MapReuce作业的从开始到结束--第2章 启动Hadoop
- 第十三周上机实践项目——fibnacci序列(递归法)
- Hdu 1195 Open the Lock [Bfs]
- Binary Tree Inorder Traversal 二叉树中序遍历@LeetCode
- UVa 10131 Is Bigger Smarter? (DP&LIS)
- jQuery的动画效果以及图片切换实例
- JAVA导出数据到excel中大数据量的解决方法
- OpenStack_Havana_Install_Guide 多节点安装总结3
- 基于iOS上MDM技术相关资料整理及汇总
- js基础 及BOM
- 电子邮件营销之EDM发送量决策问题
- IOS 5编程 内存管理 ARC技术概述
- OpenStack_Havana_Install_Guide 多节点安装总结4