题解 | #合唱队形#

合唱队形

https://www.nowcoder.com/practice/0045cd3e39634a66ada63c2adeb49234

最高峰可能在中间,也可能在两边,求最大值

public static Integer dp(int b[]) {

        int []b1 = new int[b.length];  //左至右递增

        int []b2 = new int[b.length];  //右至左递增

        b1[0] = 1;

        b2[b2.length - 1] = 1;

        int max = 0;

        for (int i = 1; i < b.length; i++) {

            b1[i] = 1;

            b2[b.length - i - 1] = 1;

            for (int j = i - 1; j >= 0 ; j--) {

                if (b[i] > b[j])

                    b1[i] = Math.max(b1[j] + 1,b1[i]);

                if (b[b.length - 1 - i] > b[b.length - i + j])

                    b2[b.length - 1 - i] = Math.max(b2[b.length - i + j] + 1,b2[b.length - 1 - i]);

            }

        }

        for (int i = 0 ; i < b.length ; i ++) {

            max = Math.max(b1[i] + b2[i], max);   //中间最大  中间 - 1

        }

        max = Math.max(max-1, Math.max(b1[b.length - 1], b2[0]));     //边缘最大  

        return b.length - max;

    }

全部评论

相关推荐

我的offer呢😡:这不才9月吗,26到明年毕业前能一直找啊,能拿下提前批,转正的,offer打牌的都是有两把刷子的,为什么非要跟他们比。如果别人是9本硕+金牌+好几段大厂实习呢?如果别人是双非通天代呢?如果别人是速通哥呢?,做好自己就行了,我们做不到他们一样提前杀死比赛,但晚点到终点也没啥关系吧
双非应该如何逆袭?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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