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 The bigger an elephant is, the smarter it is. To disprove this is the want to take the data on a collection of elephants and put as large a subset of this data as Possibl e into a sequence so this weights are increasing, but the IQ ' s are decreasing.
The input would consist of data for a bunch of elephants, one elephant per line, terminated by the end-of-file. The data for a particular elephant would consist of a pair of integers:the A, its size in representing and th e second representing its IQ in hundredths of IQ points. Both integers are between 1 and 10000. The data would contain information for at most 1000 elephants. Two elephants may have the same weight, the same IQ, or even the same and IQ.
Say that's numbers on the i-th data line are w[i] and s[i]. Your program should output a sequence of lines of data; The should contain a numbern; The remaining n lines should each contain a single positive integer (each one representing a elephant). If Thesen integers are a[1], a[2],..., A[n] Then it must is the case
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 as large as possible. All inequalities are strict:weights must is strictly increasing, and IQs must. There May is many correct outputs for a given input, and your program only needs to find one.
Sample Input
6008 1300 6000 2100 A 1000 4000 1100 3000 6000 8000 1400 6000 1200
2000 1900
Sample Output
4
4
5
9
7
How to sort? The first and second can be all from the top to the top.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
Complete code:
/*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 is the same row is to facilitate the back of the DP when not to determine whether the Wei equal ~}} 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; }