题解 | #合唱队#

合唱队

https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4

using System;

using System.Linq;

namespace HJ24

{

    internal class Program

    {

        static void Main(string[] args)

        {

            string strCount = Console.ReadLine();

            int count = int.Parse(strCount);

            string strHeight = Console.ReadLine();

            string[] strHeights = strHeight.Split();

            int[] height = new int[count];

            for (int i = 0; i < height.Length; i++)

            {

                height[i] = int.Parse(strHeights[i]);

            }

            //递增规划

            int[] dpIncre = new int[count];

            //递减规划

            int[] dpDecre = new int[count];

            //双边规划和

            int[] dpSum = new int[count];

            for (int i = 1; i < height.Length; i++)

            {

                //加上自身形成递增数列的数据数目至少为1

                dpIncre[i] = 1;

                for (int j = 0; j < i; j++)

                {

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

                    {

                        //假设之前已经规划过,已经形成了递增数列,

                        //而这次规划的递增数目应该在之前的基础上+1,因为这次身高也是递增

                        int currentIncreCount = dpIncre[j] + 1;

                        //如果这次规划的递增数目大于之前的规划,那么使用这次数目,尽量求最大的递增数目

                        if (currentIncreCount > dpIncre[i])

                        {

                            dpIncre[i] = currentIncreCount;

                        }

                    }

                }

            }

            //反向递增,顺向递减

            for (int i = height.Length - 2; i > 0; i--)

            {

                //加上自身形成递增数列的数据数目至少为1

                dpDecre[i] = 1;

                for (int j = height.Length - 1; j > i; j--)

                {

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

                    {

                        //假设之前已经规划过,已经形成了递减数列,

                        //而这次规划的递减数目应该在之前的基础上+1,因为这次身高也是递减

                        int currentDecreCount = dpDecre[j] + 1;

                        //如果这次规划的递增数目大于之前的规划,那么使用这次数目,尽量求最大的递增数目

                        if (currentDecreCount > dpDecre[i])

                        {

                            dpDecre[i] = currentDecreCount;

                        }

                    }

                }

            }

            for (int i = 0; i < count; i++)

            {

                dpSum[i] = dpIncre[i] + dpDecre[i];

            }

            //自身被规划过两次,因此要减去一次

            int max = dpSum.Max() - 1;

            int outCount = height.Length - max;

            Console.WriteLine(outCount);

        }

    }

}

全部评论

相关推荐

05-12 11:09
已编辑
门头沟学院 后端
已注销:没必要放这么多专业技能的描述。这些应该是默认已会的,写这么多行感觉在凑内容。项目这块感觉再包装包装吧,换个名字,虽然大家的项目基本都是网上套壳的,但是你这也太明显了。放一个业务项目,再放一个技术项目。技术项目,例如中间件的一些扩展和尝试。
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在午休:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
06-26 19:47
中南大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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