CF833B.The Bakery

提高+/省选-

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery.

Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable to pack cakes in boxes, and that the more distinct cake types a box contains (let's denote this number as the value of the box), the higher price it has.

She needs to change the production technology! The problem is that the oven chooses the cake types on its own and Slastyona can't affect it. However, she knows the types and order of n cakes the oven is going to bake today. Slastyona has to pack exactly k boxes with cakes today, and she has to put in each box several (at least one) cakes the oven produced one right after another (in other words, she has to put in a box a continuous segment of cakes).

Slastyona wants to maximize the total value of all boxes with cakes. Help her determine this maximum possible total value.

不久前,甜点师斯拉丝托娜决定开设自己的面包店!她购置了所需原料以及一台神奇烤箱——该烤箱能同时烘烤多种蛋糕,并正式开业。

然而不久后,支出便开始超过收入,于是斯拉丝托娜决定深入研究甜点市场。她发现,将蛋糕装入礼盒销售更为盈利;且一个礼盒中所含不同种类蛋糕的数量(我们称其为该礼盒的“价值”)越高,售价就越高。

她必须改进生产工艺!但问题在于:烤箱会自主决定所烘烤蛋糕的种类,斯拉丝托娜无法干预。不过,她已知晓今天烤箱将按顺序烘烤的 nn 个蛋糕的种类。

斯拉丝托娜今天必须恰好打包 kk 个礼盒,且每个礼盒中必须装入若干个(至少一个)连续生产的蛋糕(即每个礼盒对应原序列中的一个连续子段)。

斯拉丝托娜希望最大化所有礼盒的总价值。请帮助她确定这一最大可能的总价值。

输入格式

The first line contains two integers n and k (1 ≤ n ≤ 35000, 1 ≤ k ≤ min(n, 50)) – the number of cakes and the number of boxes, respectively.

The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ n) – the types of cakes in the order the oven bakes them.

第一行包含两个整数 nn 和 kk(1 ≤ n ≤ 350001 \leq n \leq 35000,1 ≤ k ≤ min⁡(n, 50)1 \leq k \leq \min(n, 50))——分别表示蛋糕的总数和盒子的数量。

第二行包含 nn 个整数 a1, a2, ..., ana_1, a_2, ..., a_n(1 ≤ ai ≤ n1 \leq a_i \leq n)——表示烤箱按顺序烘烤出的蛋糕类型。

输出格式

Print the only integer – the maximum total value of all boxes with cakes.

输出唯一的整数——所有装有蛋糕的盒子的总价值的最大值。

输入输出样例

  • 输入#1

    4 1
    1 2 2 1

    输出#1

    2
  • 输入#2

    7 2
    1 3 3 1 4 4 4

    输出#2

    5
  • 输入#3

    8 3
    7 7 8 7 7 8 1 7

    输出#3

    6

说明/提示

In the first example Slastyona has only one box. She has to put all cakes in it, so that there are two types of cakes in the box, so the value is equal to 2.

In the second example it is profitable to put the first two cakes in the first box, and all the rest in the second. There are two distinct types in the first box, and three in the second box then, so the total value is 5.

在第一个例子中,Slas­ty­o­na 只有一个盒子。她必须将所有蛋糕都放入该盒子中,因此盒中有两种类型的蛋糕,故得分为 2。

在第二个例子中,将前两个蛋糕放入第一个盒子、其余所有蛋糕放入第二个盒子是最优策略。此时第一个盒子中有两种不同的蛋糕类型,第二个盒子中有三种不同的蛋糕类型,因此总得分为 5。

输入解题思路,AI测评打分。不知道怎么写?

首页