Copying Books
Time Limit: 3000MS
Memory Limit: 10000K
Total Submissions: 7109
Accepted: 2221

Description

Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been
given a book and after several months he finished its copy. One of the most famous scribers lived in the 15th century and his name was Xaverius Endricus Remius Ontius Xendrianus (Xerox). Anyway, the work was very annoying and boring. And the only way to speed
it up was to hire more scribers. 



Once upon a time, there was a theater ensemble that wanted to play famous Antique Tragedies. The scripts of these plays were divided into many books and actors needed more copies of them, of course. So they hired many scribers to make copies of these books.
Imagine you have m books (numbered 1, 2 ... m) that may have different number of pages (p1, p2 ... pm) and you want to make one copy of each of them. Your task is to divide these books among k scribes, k <= m. Each book can be assigned to a single scriber
only, and every scriber must get a continuous sequence of books. That means, there exists an increasing succession of numbers 0 = b0 < b1 < b2, ... < bk-1 <= bk = m such that i-th scriber gets a sequence of books with numbers between bi-1+1 and
bi. The time needed to make a copy of all the books is determined by the scriber who was assigned the most work. Therefore, our goal is to minimize the maximum number of pages assigned to a single scriber. Your task is to find the optimal assignment. 

Input

The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly two lines. At the first line,
there are two integers m and k, 1 <= k <= m <= 500. At the second line, there are integers p1, p2, ... pm separated by spaces. All these values are positive and less than 10000000.

Output

For each case, print exactly one line. The line must contain the input succession p1, p2, ... pm divided into exactly k parts such that the maximum sum of a single part should
be as small as possible. Use the slash character ('/') to separate the parts. There must be exactly one space character between any two successive numbers and between the number and the slash. 



If there is more than one solution, print the one that minimizes the work assigned to the first scriber, then to the second scriber etc. But each scriber must be assigned at least one book.

Sample Input

2
9 3
100 200 300 400 500 600 700 800 900
5 4
100 100 100 100 100

Sample Output

100 200 300 400 500 / 600 700 / 800 900
100 / 100 / 100 / 100 100

Source

题意  k个人复制m本书  求最小的时间   即把m个数分成k份  使和最大的那份最小

d[i][j]表示i个人完毕前j本书须要的时间  有转移方程d[i][j]=min(d[i][j],max(d[i-1][k],s[j]-s[k]))  k表示i-1到j之间的全部数  s[k]表示从第一本书到第k本书须要时间的和  初始d[1][i]=s[i];

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 550, INF = 0x3f3f3f3f;
int a[N], flag[N], s[N], d[N][N], t, cas, n, m, ans;
int dp (int i, int j)
{
if (d[i][j] > 0) return d[i][j];
d[i][j] = INF;
for (int k = i - 1; k < j; ++k)
d[i][j] = min (d[i][j], max (dp (i - 1, k), s[j] - s[k]));
return d[i][j];
} int main()
{
scanf ("%d", &cas);
while (cas--)
{
scanf ("%d%d", &n, &m);
memset (d, -1, sizeof (d)); memset (flag, -1, sizeof (flag));
for (int i = 1; i <= n; ++i)
{ scanf ("%d", &a[i]); d[1][i] = s[i] = s[i - 1] + a[i]; }
ans = dp (m, n); for (int i = n,t=0 ; i >= 1; --i)
if ( ( (t = t + a[i]) > ans) || m > i)
{ t = a[i]; flag[i] = 0; --m; }
for (int i = 1; i <= n; ++i)
{
printf (flag[i] ? "%d" : "%d /", a[i]);
printf (i == n ? "\n" : " ");
}
}
return 0;
}

POJ1505&amp;&amp;UVa714 Copying Books(DP)的更多相关文章

  1. poj 1505 Copying Books

    http://poj.org/problem?id=1505 Copying Books Time Limit: 3000MS   Memory Limit: 10000K Total Submiss ...

  2. Copying Books

    Copying Books 给出一个长度为m的序列\(\{a_i\}\),将其划分成k个区间,求区间和的最大值的最小值对应的方案,多种方案,则按从左到右的区间长度尽可能小(也就是从左到右区间长度构成的 ...

  3. UVa 714 Copying Books(二分)

    题目链接: 传送门 Copying Books Time Limit: 3000MS     Memory Limit: 32768 KB Description Before the inventi ...

  4. 抄书 Copying Books UVa 714

    Copying  Books 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/B 题目: Descri ...

  5. UVA 714 Copying Books 二分

    题目链接: 题目 Copying Books Time limit: 3.000 seconds 问题描述 Before the invention of book-printing, it was ...

  6. uva 714 Copying Books(二分法求最大值最小化)

    题目连接:714 - Copying Books 题目大意:将一个个数为n的序列分割成m份,要求这m份中的每份中值(该份中的元素和)最大值最小, 输出切割方式,有多种情况输出使得越前面越小的情况. 解 ...

  7. UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)

      Copying Books  Before the invention of book-printing, it was very hard to make a copy of a book. A ...

  8. POJ1505:Copying Books(区间DP)

    Description Before the invention of book-printing, it was very hard to make a copy of a book. All th ...

  9. 高效算法——B 抄书 copying books,uva714

    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description ...

随机推荐

  1. Android如何监听蓝牙耳机的按键事件

    写在前面: 直接想要代码很简单,你直接把滚动条拉到最底端就可以看到.如果想要十分地了解为什么,那就按照我规划的一步一步来理解.以下测试环境以手头上有的「Bluedio + 红米手机」. 1.蓝牙耳机的 ...

  2. Linux内核-系统调用

    Linux内核-系统调用 1.与内核通信 #系统调用在用户空间进程和硬件设备之间添加了一个中间层 作用:1.为用户空间提供了一种硬件的抽象接口 2.系统调用保证了系统的稳定和安全 3.出于每一个进程都 ...

  3. android 屏幕尺寸的理解

    对android设备屏幕尺寸单位的理解 一.android移动设备(手机和平板)常用的关于屏幕的一些单位: 1.px:像素点,应该是一个统一的单位,与我们国际单位米(M)应该是一回事,它应该是屏幕尺寸 ...

  4. jQuery选择器——全新的总结方式

    jQuery 选择器的总结 用于定位的选择器: 基本选择器:(用来进行绝对定位) $("#myELement")    选择id值等于myElement的元素,id值不能重复在文档 ...

  5. 解决Charles Response 中文乱码

    Response中文乱码:在Info.plist 中 的vmoption 添加-Dfile.encoding=UTF-8 info.plist路径 应用程序->Charles.app->显 ...

  6. C++操作符的优先级

    C++操作符的优先级 C++操作符的优先级 操作符及其结合性 功能 用法 L L L :: :: :: 全局作用域 类作用域 名字空间作用域 ::name class::name namespace: ...

  7. asp.net2.0安全性(2)--用户个性化设置(2)--转载来自车老师

    上一篇我们用Profile.age等方式可以读取用户的年龄和其它的信息,但有的时候我们要查询显示所有用户的信息,但asp.net没有提供查询所有用户信息的功能,我们只能对现有的用户逐一查询其Profi ...

  8. string的不可变性

    1.不可变性 代码如下: static void Main(string[] args){string str1 = "a";string str2 = str1;str2 = & ...

  9. 服务确定(服务类收货ML81N)

    FUNCTION zrfc_mm005. *"---------------------------------------------------------------------- * ...

  10. android 使用Scroller实现缓慢移动

    在Launcher中的Workspace中实现了左右屏幕切换效果,里面就用到了Scroller记录滑动轨迹,实现一种缓慢地向左或向右移动的效果,这里我对这种效果进行总结: 我们先看一个例子:点击按钮时 ...