The Painter's Partition Problem Part I

You have to paint N boards of lenght {A0, A1, A2 ... AN-1}. There are K painters available and you are also given how much time a painter takes to paint 1 unit of board. You have to get this job done as soon as possible under the constraints that any painter will only paint continues sections of board, say board {2, 3, 4} or only board {1} or nothing but not board {2, 4, 5}.

We define M[n, k] as the optimum cost of a partition arrangement with n total blocks from the first block and k patitions, so

                 n              n-1M[n, k] = min { max { M[j, k-1],  Ai } }
                j=1             i=j

The base cases are:

M[1, k] = A0
         n-1
M[n, 1] = Σ Ai         i=0

Therefore, the brute force solution is:

int sum(int A[], int from, int to)
{
    int total = 0;
    for (int i = from; i <= to; i++)
        total += A[i];
    return total;
}

int partition(int A[], int n, int k)
{
    if (n <= 0 || k <= 0)
        return -1;
    if (n == 1)
        return A[0];
    if (k == 1)
        return sum(A, 0, n-1);

    int best = INT_MAX;
    for (int j = 1; j <= n; j++)
        best = min(best, max(partition(A, j, k-1), sum(A, j, n-1)));

    return best;
}

The Painter's Partition Problem Part I

时间: 2024-10-03 08:57:02

The Painter's Partition Problem Part I的相关文章

poj 1681 Painter&amp;#39;s Problem(高斯消元)

http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. 注意依据自由变元求其它解及求最优值的方法. #include <stdio.h> #include <algorithm> #include <set> #include <map> #include <vector> #include <math.h> #include

算法归类和总结

一.DP问题: 1.字符串编辑距离. http://www.cnblogs.com/litao-tech/p/4121878.html 2.字符串的组合个数. http://www.cnblogs.com/litao-tech/p/4160368.html 3.求一维数组中不重叠的两个子数组的最大和. http://www.cnblogs.com/litao-tech/p/4163576.html 4.The Painter's Partition Problem Part I. http://

[BestCoder Round #6] hdu 4982 Goffi and Squary Partition(构造)

Goffi and Squary Partition Problem Description Recently, Goffi is interested in squary partition of integers. A set X of k distinct positive integers is called squary partition of n if and only if it satisfies the following conditions: the sum of k p

Linux 高可用(HA)集群之Heartbeat安装

大纲一.Heartbeat 的定义二.Heartbeat 的版本与组件三.Heartbeat 的各版本之间的区别 四.Heartbeat 集群的一般拓扑图 五.安装heartbeat 六.配置heartbeat 七.使用集群的其他几个相关配置 八.实验 推荐阅读: CentOS 6.3下DRBD+Heartbeat+NFS配置笔记 http://www.linuxidc.com/Linux/2013-06/85599.htm Heartbeat_ldirector+LB+NFS实现HA及LB.文

MySQL+DRBD+heartbeat+LVS+keepalived

在node1上的操作:[[email protected] 桌面]# iptables -F[[email protected] 桌面]# chkconfig iptables off[[email protected] 桌面]# setenforce 0[[email protected] 桌面]# ip addr show1: lo: mtu 16436 qdisc noqueue state UNKNOWN     link/loopback 00:00:00:00:00:00 brd 0

heartbeat3.0 for oracle

操作系统版本:centos6.5 64bit [[email protected] ~]# Linux centos1 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux 所有节点IP信息 [[email protected] ~]# more /etc/hosts127.0.0.1 localhost 192.168.1.241 centos1192.168.1.242

前端小白的算法之路

时隔多日终于解决了埋在心头的一道难题,霎时云开雾散,今天把一路而来碰到的疑惑和心得都记录下来,也算是开启了自己探索算法的大门. 问题背景 曾经有一个年少轻狂的职场小白,在前端圈子里摸爬滚打将近两年,本计划在js的道路上越走越远,以至于每天沉浸在js红皮书里不能自拔,突然有一天脑抽想找leader比划两下,于是出现了下面的对话,小白:leader,您最近在干嘛?手里有需要亟待解决的难题吗?leader:咦,确实有哎,咱的项目随着业务的不断发展,日均PV也越来越多,公司的两台机器已经快满足不了需求,

Bubblesort and oblivious

Problem 12. (Difficulty 2) Bubblesort and oblivious merge-sort each give a sequence ofcompare-exchange operations which sorts any array A[0..3]. Write down both sequences.Problem 13. (Difficulty 4) For n distinct elements x1, x2, . . . , xn with posi

2019nc#2

A Eddy Walker 题意 你有n个点(0-n-1),按顺序形成一个环,初始时你在0的位子,你随机顺时针走一步或者逆时针走一步, 一旦你走到一个点后,环上所有点都被经过至少一次后,你就必须停下来. 问你最后停留在m这个位子的概率是多少. 思路 有意思的概率题. 读懂题意后发现这道题不难,模拟下可以发现在最后落在(1-n-1)的位子是等概率的,落在0这个位子是不可能的(除非n==1). #include <iostream> #include <vector> #include