uva 10131 最长子序列
来源:互联网 发布:w3cschool php教程 编辑:程序博客网 时间:2024/05/20 18:44
题意:
给大象的体重和智商,求体重按从大到小,智商从高到低的最长子序列,并输出路径。
代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <queue>#include <map>#define LL long longusing namespace std;const int maxn = 1e3 + 10;const int inf = 0x3f3f3f3f;const double eps = 1e-8;const double pi = 4 * atan(1.0);const double ee = exp(1.0);struct Elephant{ int w; int iq; int r;} e[maxn];bool cmp(Elephant a, Elephant b){ return a.w > b.w;}int dp[maxn];int n;int path[maxn];int ans;void print(int i, int dep){ if (dep == ans) return; printf("%d\n", e[i].r); print(path[i], dep + 1); //printf("%d\n", e[i].r);}int main(){ #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL n = 1; while (scanf("%d%d", &e[n].w, &e[n].iq) != EOF) { e[n].r = n; n++; } sort(e + 1, e + n + 1, cmp); dp[0] = 0; for (int i = 1; i < n; i++) { // cout << e[i].w << " " <<e[i].iq << " " << e[i].r << endl; dp[i] = 1; path[i] = i; for (int j = 1; j < i; j++) { if (e[i].iq > e[j].iq && dp[i] < dp[j] + 1 && e[i].w < e[j].w) { dp[i] = dp[j] + 1; path[i] = j; } } } ans = -1; int pos = 0; for (int i = 1; i < n; i++) { if (ans < dp[i]) { pos = i; ans = dp[i]; } } printf("%d\n", ans); print(pos, 0); return 0;}
0 0
- uva 10131 最长子序列
- uva 10131(最长递增子序列)
- 【动态规划】最长递增子序列代码(UVA 10131)
- Uva 10131 Is Bigger Smarter 最长递减子序列
- UVA - 10131 Is Bigger Smarter? 最长上升子序列
- 最长公共子序列uva--111
- UVA 231 最长下降子序列
- Vacation - UVa 10192 最长公共子序列
- uva 111(最长公共子序列)
- uva 10405(最长公共子序列)
- uva 10066(最长公共子序列)
- uva 10192(最长公共子序列)
- uva 531(最长公共子序列)
- uva 437(最长递减子序列)
- uva 10051(最长上升子序列)
- uva 10635(最长公共子序列nlogn)
- uva 10534 nlogn最长上升子序列
- uva 10635(最长上升子序列)
- 拿到乐视offer
- verilog pli 使用注意事项
- 插入排序
- 【BZOJ2435】【Noi2011】道路修建 树形DP
- CSS3 Transform
- uva 10131 最长子序列
- 正则表达式
- Struts2
- windows系统下Python环境的搭建
- hdu 1421 搬寝室
- 对象及其内存管理
- 黑马程序员--集合框架---泛型限定
- leetcode--Best Time to Buy and Sell Stock II
- 10730-Antiarithmetic?【暴力枚举】