CF321E.Ciel and Gondolas

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Fox Ciel is in the Amusement Park. And now she is in a queue in front of the Ferris wheel. There are nn people (or foxes more precisely) in the queue: we use first people to refer one at the head of the queue, and nn -th people to refer the last one in the queue.

There will be kk gondolas, and the way we allocate gondolas looks like this:

  • When the first gondolas come, the q1q_{1} people in head of the queue go into the gondolas.
  • Then when the second gondolas come, the q2q_{2} people in head of the remain queue go into the gondolas. ...
  • The remain qkq_{k} people go into the last ( kk -th) gondolas.

Note that q1q_{1} , q2q_{2} , ..., qkq_{k} must be positive. You can get from the statement that and qi>0q_{i}>0 .

You know, people don't want to stay with strangers in the gondolas, so your task is to find an optimal allocation way (that is find an optimal sequence qq ) to make people happy. For every pair of people ii and jj , there exists a value uiju_{ij} denotes a level of unfamiliar. You can assume uij=ujiu_{ij}=u_{ji} for all i,ji,j (1<=i,j<=n)(1<=i,j<=n) and uii=0u_{ii}=0 for all ii (1<=i<=n)(1<=i<=n) . Then an unfamiliar value of a gondolas is the sum of the levels of unfamiliar between any pair of people that is into the gondolas.

A total unfamiliar value is the sum of unfamiliar values for all gondolas. Help Fox Ciel to find the minimal possible total unfamiliar value for some optimal allocation.

输入格式

The first line contains two integers nn and kk ( 1<=n<=40001<=n<=4000 and 1<=k<=min(n,800)1<=k<=min(n,800) ) — the number of people in the queue and the number of gondolas. Each of the following nn lines contains nn integers — matrix uu , ( 0<=uij<=90<=u_{ij}<=9 , uij=ujiu_{ij}=u_{ji} and uii=0u_{ii}=0 ).

Please, use fast input methods (for example, please use BufferedReader instead of Scanner for Java).

输出格式

Print an integer — the minimal possible total unfamiliar value.

输入输出样例

  • 输入#1

    5 2
    0 0 1 1 1
    0 0 1 1 1
    1 1 0 0 0
    1 1 0 0 0
    1 1 0 0 0
    

    输出#1

    0
    
  • 输入#2

    8 3
    0 1 1 1 1 1 1 1
    1 0 1 1 1 1 1 1
    1 1 0 1 1 1 1 1
    1 1 1 0 1 1 1 1
    1 1 1 1 0 1 1 1
    1 1 1 1 1 0 1 1
    1 1 1 1 1 1 0 1
    1 1 1 1 1 1 1 0
    

    输出#2

    7
    
  • 输入#3

    3 2
    0 2 0
    2 0 3
    0 3 0
    

    输出#3

    2
    

说明/提示

In the first example, we can allocate people like this: {1, 2} goes into a gondolas, {3, 4, 5} goes into another gondolas.

In the second example, an optimal solution is : {1, 2, 3} | {4, 5, 6} | {7, 8}.

首页