要求:叠罗汉过程中,站在某个人肩上的人应该既比自己矮又比自己瘦,或相等。
*/
public class CircusTroup {
static class People{
int num;
int weight;
int height;
public People(int num,int weight,int height){
this.num=num;
this.weight=weight;
this.height=height;
}
}
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int N;
while (scanner.hasNext()){
N=scanner.nextInt();
String inValid=scanner.nextLine();//无效
People[] peoples=new People[N];
for(int i=0;i
String[] str=scanner.nextLine().split(" ");
peoples[i]=new People(Integer.valueOf(str[0]),Integer.valueOf(str[1]),Integer.valueOf(str[2]));
}
//第一处:注意地方
//先按照体重升序,再按照身高降序
//为什么身高要降序?因为:体重相同时,只有身高也相同才可以站在自己肩上,比自己矮是不能站在自己肩上的。
//而身高降序就保证了:体重相同时,身高不同为降序,不是升序序列,则不能站在自己肩上.
Arrays.sort(peoples,new Comparator() {
@Override
public int compare(People o1,People o2) {
if(o1.weight==o2.weight){
return o2.height-o1.height;
}else{
return o1.weight-o2.weight;
}
}
});
//第二处:注意地方 db部分开始
//按身高求最大升序子序列,不是太会
int[] dp=new int[N];
dp[0]=1;
int level=0;
for(int i=1;i
dp[i]=1;
for(int j=0;j代码,可以知道:子序列并不需要连续,只要满足if条件就可以
if(peoples[j].height<=peoples[i].height && dp[j]+1>dp[i])
dp[i]=dp[j]+1;
}
}
Arrays.sort(dp);
level=dp[N-1];
System.out.println(level);
}
}
}