#P7084. [NWRRC2013] Flight Boarding Optimization

[NWRRC2013] Flight Boarding Optimization

题目描述

Peter is an executive boarding manager in Byteland airport. His job is to optimize the boarding process. The planes in Byteland have ss rows, numbered from 11 to ss . Every row has six seats, labeled A to FF .

There are nn passengers, they form a queue and board the plane one by one. If the i-th passenger sits in a row rir_{i} then the difficulty of boarding for him is equal to the number of passengers boarded before him and sit in rows 11 . . . ri1r_{i}−1 . The total difficulty of the boarding is the sum of difficulties for all passengers. For example, if there are ten passengers, and their seats are 6A,4B,2E,5F,2A,3F,1C,10E,8B,5A,6A, 4B, 2E, 5F, 2A, 3F, 1C, 10E, 8B, 5A, in the queue order, then the difficulties of their boarding are 0,0,0,2,0,2,0,7,7,50 , 0 , 0 , 2 , 0 , 2 , 0 , 7 , 7 , 5 , and the total difficulty is 2323 .

To optimize the boarding, Peter wants to divide the plane into kk zones. Every zone must be a continuous range of rows. Than the boarding process is performed in kk phases. On every phase, one zone is selected and passengers whose seats are in this zone are boarding in the order they were in the initial queue.   

In the example above, if we divide the plane into two zones: rows 5105-10 and rows 141-4 , then during the first phase the passengers will take seats 6A,5F,10E,8B,5A,6A, 5F, 10E, 8B, 5A, and during the second phase the passengers will take seats 4B,2E,2A,3F,1C,4B, 2E, 2A, 3F, 1C, in this order. The total difficulty of the boarding will be 66 .

Help Peter to find the division of the plane into kk zones which minimizes the total difficulty of the boarding, given a specific queue of passengers.

输入格式

The first line contains three integers n(1n1000),s(1s1000)n (1 \le n \le 1000) , s (1 \le s \le 1000) , and k(1k50k (1 \le k \le 50 ; ks)k \le s) . The next line contains nn integers ri(1ris)r_{i} (1 \le r_{i} \le s) .

Each row is occupied by at most 66 passengers.

输出格式

Output one number, the minimal possible difficulty of the boarding.

题目大意

题目描述

Peter是 Byteland 机场的高级登机管理人员。他的工作是优化登机流程。Byteland 中的飞机有ss行,编号从1到ss。每排有六个座位,标有AAFF

nn名乘客,他们排成一队,一个接一个地登上飞机。如果第ii位乘客坐在第rir_i排,那么,他登机的难度等于在他前面登机的并且坐在第1......rir_i $-$1排的乘客人数之和。

登机的总难度是所有乘客的登机难度之和。例如,如果有十名乘客,他们的座位分别是6A4B2E5F2A3F1C10E8B5A6A、4B、2E、5F、2A、3F、1C、10E、8B、5A,按照排队顺序排列,那么他们登机的难度分别是00020207750、0、0、2、0、2、0、7、7、5,总难度是2323

为了优化登机,Peter希望将飞机划分成kk个区域。每个分区都必须是连续的行数。然后分成kk段执行登机流程。在每个阶段,选择一个区域,座位在该区域的乘客将按照他们在初始队列中的顺序登机。

在上面的示例中,如果我们将平面划分为两个区域:第 5105-10 行和第141-4 行,则在第一阶段,乘客将依次就座6A5F10E8B5A6A、5F、10E、8B、5A。在第二阶段,乘客将依次就座4B2E2A3F1C4B、2E、2A、3F、1C。登机的总难度为66

帮助Peter找到将飞机划分为kk个区域的方法,在给定特定乘客队列的情况下,将登机的总难度降至最低。

输入格式

第一行包括三个整数n(1n1000)n(1≤n≤1000),s(1s1000)s(1≤s≤1000)k(1k1000)k(1≤k≤1000)

第二行包括nn个整数ri(1ris)r_i(1≤r_i≤s)

输出格式

输出一行一个数,最小的登机总难度

10 12 2
6 4 2 5 2 3 1 11 8 5

6

提示

Time limit: 2 s, Memory limit: 256 MB.