2020-03-20 17:40:39 +08:00

24 lines
607 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 马房分配
[问题描述]
一个农夫要把 n 只马分配到 k 个马房里,放置的规则是:如果第 1 到第 i 只马放入第一个马房那么第i+1到第j只放入第二个马房接下来第j+1至第p只马放入第三个马房......,以此类推。此外对于每一个马房都有一个叫做“不高兴系数”,即白色马的数量*黑色马的数量。
你的任务是合理地分配这 n 只马,使得它所有马房的“不高兴系数”和最小。
[输入格式]
第一行有 2 个整数n(1≤n≤500)和 k(1≤k≤)。接下来的 n 行有 n 个数。第 i 行为第 i
只马的颜色1 是黑色0 是白色。
[输出格式]
输出最小的“不高兴系数”的总和。
[输入样例]
6 3
1
1
0
1
0
1
[输出样例]
2