题解 | #Redraiment的走法#

Redraiment的走法

https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa

import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i1 = Integer.parseInt(scanner.nextLine());
        int[] all = new int[i1];
        String[] s = scanner.nextLine().split(" ");
        for (int i = 0; i < s.length; i++) {
            all[i] = Integer.parseInt(s[i]);
        }
        HashSet<Integer> result = new HashSet<>();
        for (int i = 0; i < all.length; i++) {
            result.add(dp(i, all));
        }
        System.out.println(result.size() > 0 ? Collections.max(result).intValue() : 1);
    }

    public static int dp(int index, int[] all) {
        HashSet<Integer> result = new HashSet<>();
        for (int i = index; i < all.length; i++) {
            if (all[index] < all[i]) {
                result.add(dp(i, all) + 1);
            }
        }
        return result.size() > 0 ? Collections.max(result) : 1;
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 18:05
哈哈哈哈哈感觉朋友找工作的已经疯掉了,直接上图
码农索隆:真老板娘:“我嘞个去,这不我当年的套路吗
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 13:54
点赞 评论 收藏
分享
程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务