10131 - Is Bigger Smarter? 水dp
来源:互联网 发布:爱股轩软件下载 编辑:程序博客网 时间:2024/06/04 18:52
Question 1: Is Bigger Smarter?
The Problem
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 number n; the remaining n lines should each contain a single positive integer (each one representing an elephant). If these n 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---------
-----------
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct EL{ int x; int y; int id;}a[11111];bool cmp(EL a,EL b){ if (a.x==b.x) return a.id<b.id; return a.x<b.x;}int n;int f[11111]={0};int p[11111]={0};int ans[11111]={0};int cnt;int main(){ n=1; while (~scanf("%d%d",&a[n].x,&a[n].y)){a[n].id=n;n++;} n--; sort(a+1,a+n+1,cmp); int mx=0; int ww=0; //for (int i=1;i<=n;i++){cerr<<a[i].x<<" "<<a[i].y<<" "<<a[i].id<<endl;} for (int i=1;i<=n;i++) { f[i]=1; p[i]=0; for (int k=1;k<i;k++) { if (a[i].y<a[k].y&&a[i].x>a[k].x&&f[k]+1>f[i]) { f[i]=f[k]+1; p[i]=k; } } if (f[i]>mx) { mx=f[i]; ww=i; } } //for (int i=1;i<=n;i++) cerr<<f[i]<<" ";cerr<<endl; printf("%d\n",mx); cnt=0; while (ww!=0) { ans[cnt++]=a[ww].id; ww=p[ww]; } for (int i=cnt-1;i>=0;i--) { printf("%d\n",ans[i]); } return 0;}
- 10131 - Is Bigger Smarter? 水dp
- UVA 10131 Is Bigger Smarter? DP
- UVa 10131 Is Bigger Smarter? (DP&LIS)
- UVA 10131 Is Bigger Smarter ? DP ,Commencel
- UVA 10131 Is Bigger Smarter? (DP)
- Is Bigger Smarter? - UVa 10131 dp
- 【DP】UVA 10131 Is Bigger Smarter? LIS
- UVA 10131 Is Bigger Smarter?(DP)
- Uva 10131-Is Bigger Smarter?(DP)
- uva--10131Is Bigger Smarter? +dp
- 10131 - Is Bigger Smarter?
- 10131 - Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter? 越大越聪明? dp,LDS
- UVA - 10131Is Bigger Smarter?(DAG上的DP)
- UVa 10131 Is Bigger Smarter?
- UVa 10131 Is Bigger Smarter?
- UVA 10131 - Is Bigger Smarter
- uva 10131 Is Bigger Smarter?
- CKEditor3.0-4.0 js版编辑器,调用取值赋值等基本应用
- 理解 pkg-config 工具
- 关联容器——map
- 百度云
- 杭电2187
- 10131 - Is Bigger Smarter? 水dp
- poj2942点双连通奇圈-二分图判断Knights of the Round Table
- 求1+2+3+.....+n的几种解法
- 列表框控件——报表显示
- 依赖注入的3种实现方式
- C++ 禁止拷贝
- MySQL:讨人喜欢的 MySQL replace into 用法(insert into 的增强版)
- Android中利用ant进行多渠道循环批量打包(二)
- GDB 常用技巧