| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 808 人关注过本帖
标题:笛卡尔树问题求解
只看楼主 加入收藏
xiaohuo66
Rank: 1
等 级:新手上路
帖 子:51
专家分:0
注 册:2020-11-1
结帖率:88.89%
收藏
 问题点数:0 回复次数:0 
笛卡尔树问题求解
题解说是考察分治或动态规划

As a teammate lunch eliminator, Quasrain takes all foods before his teammates found them in every contest. In the latest contest, there are N kinds of foods on the table. The number of each kind of food is  .

Now Quasrain has two kinds of bite to eat them all.

choose two integers L and R(L <= R) then eat one from each kind of food in [L, R] with a single bite. This requires that each kind of food in [L, R] is at least one.

choose a kind K, then eat up all of food of kind K, also in a single bite. This also requires that this kind of food is at least one.

To avoid being spotted and killed, Quasrain wants to know the minimum operations for him to eat all the food.

Input
Multi testcases.

For each testcase, the first line contains one integer N (1<=N<=5000)

The second line contains N integers a1,a2...0<ai<10^9

Output
For each testcase, print one integer as the answer.

Sample Input
4
1 4 1 1
5
1 0 1 0 1


Sample Output
2
3
搜索更多相关主题的帖子: This single the one for 
2020-12-29 13:06
快速回复:笛卡尔树问题求解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014296 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved