题解 | #马戏团#
马戏团
http://www.nowcoder.com/practice/c2afcd7353f84690bb73aa6123548770
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
SH1();
}
static class Persion{
public int id;
public int weight;
public int height;
}
public static void SH1() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String ln;
while ((ln = br.readLine()) != null){
List<Persion> personList = new ArrayList<>();
int n = Integer.parseInt(ln);
int[] p = new int[n];
for (int i = 0; i < n; i++) {
String[] str = br.readLine().split(" ");
int id = Integer.parseInt(str[0]);
int weight = Integer.parseInt(str[1]);
int heigth = Integer.parseInt(str[2]);
Persion persion = new Persion();
persion.id = id;
persion.weight = weight;
persion.height = heigth;
personList.add(persion);
}
personList.sort((a,b)->{
if (a.weight - b.weight == 0){
return b.height - a.height;
}
return a.weight - b.weight;
});
int size = personList.size();
for (int i = 1; i < size; i++) {
for (int j = i - 1 ; j >= 0; j--) {
if (personList.get(j).height <= personList.get(i).height){
if (p[i] < p[j] + 1){
p[i] = p[j] + 1;
}
}
}
}
int max = 0;
for (int i = 0; i < n; i++) {
if (p[i] > max) {
max = p[i];
}
}
System.out.println(max+1);
}
}
}