UVa 10131 - Is Bigger Smarter?
来源:互联网 发布:win10上安装mac虚拟机 编辑:程序博客网 时间:2024/05/29 18:57
题目:有人认为大象的体重和智力有一定的正相关性,现在给你一些数据,找到一个最长的反例序列。
分析:dp,LIS,醉倒上升子序列。对W排序求出S的最大下降子序列即可,存储路径前驱,dfs输出。
说明:先读到EOF再处理。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;typedef struct enode{int id,w,s;}elephant;elephant E[1001];int cmp(elephant a, elephant b){if (a.w == b.w) {if (a.s == b.s)return a.id < b.id;else return a.s > b.s;}else return a.w < b.w;}int F[1001],P[1001];void output(int s,int d){if (P[s] == s) {printf("%d\n%d\n",d,E[s].id);return;}else {output(P[s], d+1);printf("%d\n",E[s].id);}}int main(){int count = 0;while (~scanf("%d%d",&E[count].w,&E[count].s)) {E[count].id = count+1;count ++;}sort(E, E+count, cmp);int spa = 0;for (int i = 0 ; i < count ; ++ i) {F[i] = 1;P[i] = i;for (int j = 0 ; j < i ; ++ j)if (E[i].w > E[j].w && E[i].s < E[j].s && F[i] < F[j]+1) {F[i] = F[j]+1;P[i] = j;}if (F[spa] < F[i]) spa = i;}output(spa, 1); return 0;}
0 0
- 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?
- 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?
- UVa:10131 Is Bigger Smarter?
- UVA - 10131 Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- 160A - Twins
- ASP.NET MVC 视图与模型绑定
- 如何避免2.4GHz ISM频段下各种无线设备的干扰
- dBm, dBi, dBd, dB, dBc
- 如何避免2.4GHz ISM频段下各种无线设备的干扰
- UVa 10131 - Is Bigger Smarter?
- 手机串号
- 数据结构关于二叉树的操作
- 【J2EE】【2.JDBC】JDBC连接数据库(MariaDB,Mysql)(继续之前jee的登陆例子)
- Direct3D纹理映射技术
- 校验码的计算方法说明
- mwArray类说明 - [Matlab VC环境下编程]
- The first time !
- 黑马程序员-函数