import java.util.*; public class Main { /** 请完成下面这个函数,实现题目要求的功能 **/     /**      * 当然,你也可以不按照这个模板来作答,完全按照自己的想法来 ^-^      **/     static int pick(int[] peaches) {         int max = 0;         int[] maxs = new int[peaches.length];         for (int i = peaches.length - 1; i >= 0; i--) {             int maxtemp = 0;             for (int j = i + 1; j < peaches.length; j++) {                 if (peaches[j] >= peaches[i] && maxs[j] > maxtemp) {                     maxtemp = maxs[j];                 }             }             int count = maxtemp + 1;             if (count > max) {                 max = count;             }             maxs[i] = count;         }         return max;     }     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         int trees = Integer.parseInt(in.nextLine().trim());         int[] peaches = new int[trees];         for (int i = 0; i < peaches.length; i++) {             peaches[i] = Integer.parseInt(in.nextLine().trim());         }         System.out.println(pick(peaches));     } }
点赞 6

相关推荐

线性袋鼠:别听牛客上一帮伪人在那说,小厂不能去,必须去大厂,听他们放屁吧。学院本+一些一本最终的归宿就是中小厂,大厂那么好进吗
我的实习日记
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务