Codeforces Round 190 (Div. 1)
E
Ciel and Gondolas
Codeforces
2600
原题
← D→
翻译中…

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

翻译中…

There will be $*k*$ gondolas, and the way we allocate gondolas looks like this:

翻译中…
  • When the first gondolas come, the $*q*_{1}$ people in head of the queue go into the gondolas.
  • Then when the second gondolas come, the $*q*_{2}$ people in head of the remain queue go into the gondolas. ...
  • The remain $*q*_{*k*}$ people go into the last ($*k*$-th) gondolas.
翻译中…

Note that $*q*_{1}$, $*q*_{2}$, ..., $*q*_{*k*}$ must be positive. You can get from the statement that image and $*q*_{*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 $*q*$) to make people happy. For every pair of people $*i*$ and $*j*$, there exists a value $*u*_{*ij*}$ denotes a level of unfamiliar. You can assume $*u*_{*ij*} = *u*_{*ji*}$ for all $*i*, *j*$ $(1 ≤ *i*, *j* ≤ *n*)$ and $*u*_{*ii*} = 0$ for all $*i*$ $(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.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*k*$ ($1 ≤ *n* ≤ 4000$ and $1 ≤ *k* ≤ *min*(*n*, 800)$) — the number of people in the queue and the number of gondolas. Each of the following $*n*$ lines contains $*n*$ integers — matrix $*u*$, ($0 ≤ *u*_{*ij*} ≤ 9$, $*u*_{*ij*} = *u*_{*ji*}$ and $*u*_{*ii*} = 0$).

翻译中…

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

翻译中…

Output

翻译中…

Print an integer — the minimal possible total unfamiliar value.

翻译中…

Note

翻译中…

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}.

翻译中…

样例

Input #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
Output #1
0
InputCopy OutputCopy
Input #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
Output #2
7
InputCopy OutputCopy
Input #3
3 2
0 2 0
2 0 3
0 3 0
Output #3
2
InputCopy OutputCopy
题目信息
题号
321E
时间限制
4 s
内存限制
512 MB
标签
数据结构
分治
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。