POJ 1505 Copying Books 动态规划


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.


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.


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

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





using namespace std;

const int MAXN = 510;
int sum[MAXN],path[MAXN],dp[MAXN][MAXN];

int main(){
int m,k,i,j,v,ca,p,t;
"%d %d",&m,&k);

for(j=1;j<=&& j<=k;j++){
if(j==1) dp[i][j]=sum[i];
if(dp[i][j]==-1 || t<=dp[i][j]) 


if(p>dp[m][k] || i<=j){


if(i>1) printf(" ");
if(j<&& path[j]==i){



return 0;

posted on 2009-06-16 09:59 极限定律 阅读(3145) 评论(12)  编辑 收藏 引用 所属分类: ACM/ICPC


# re: POJ 1505 Copying Books 动态规划 2009-06-16 22:30 bafangprinter

China-Beijing bafang printing plant,Offers business printing services ,Full colour printing service for brochures,paper bag,newsletters,magazines,catalogues,Boxprinting,Paper processing,Drugs ,Business Cards, Box,Jewel box,Gift box,Kraft paper bags,Corrugated Box,Beijing Printing, Foreigners in China ,All are welcome to the Advisory order! TEL:86-010-51665543 MSN:beijingbafang@hotmail.com http://www.print861.com Fengtai District Beijing  China   回复  更多评论   

# re: POJ 1505 Copying Books 动态规划 2009-11-17 22:21 Gamor

二分最大值也可以过。  回复  更多评论   

# re: POJ 1505 Copying Books 动态规划 2010-07-18 19:33 AnnetteKRAMER

I would like to propose not to hold back until you get enough amount of cash to buy different goods! You can just get the <a href="http://bestfinance-blog.com/topics/personal-loans">personal loans</a> or just secured loan and feel yourself comfortable   回复  更多评论   

# re: POJ 1505 Copying Books 动态规划 2010-08-02 17:01 buy essay

Study process demands creative writing skills, nevertheless, college students, which don't have time can fail their academic career. Hence, to purchase the term papers from the buy term paper service would be a right decision.   回复  更多评论   

# re: POJ 1505 Copying Books 动态规划 2010-08-05 16:36 term paper

This is what I was exploring for a long time! Thanks for this article around university! One time somebody state that In union there is effect. Our powerfully skilled service can help you in writing custom research papers.  回复  更多评论   

# re: POJ 1505 Copying Books 动态规划 2010-08-11 20:30 essay writing service

Do you work a lot on your writing assignment? You do not have to bother about that any longer, because you can buy essay papers.   回复  更多评论   

# re: POJ 1505 Copying Books 动态规划[未登录] 2010-09-25 11:15 dress

Best canon Coffee Mugs! Funny, Cute, & Humorous Unique designs. Also find Travel Mugs, Coffee Cups also, or Create Photo Personalized Mugs & Drinkware  回复  更多评论   

# re: POJ 1505 Copying Books 动态规划 2012-02-11 12:45 resume writing

The article you post by scribers is very interesting, now we understand how xerox copy machine came to being, its a great info.  回复  更多评论   

# re: POJ 1505 Copying Books 动态规划 2012-04-17 16:09 help in writing term papers

This article defines how things came to being,here i found so many information related to copying books and machines.Its nice to read this book.  回复  更多评论   

# re: POJ 1505 Copying Books 动态规划[未登录] 2013-05-12 19:40 BETTY

格式有点囧  回复  更多评论   

# re: POJ 1505 Copying Books 动态规划 2013-06-17 20:01 this site

Go to Perfect-resume company (perfect-resume.com) if you are in need of reliable resume services. Having delt with this trustable agency, you will be aware of which service to choose for buying resume and where to look through samples of resume writing. Don’t mull over, buy CV of good quality from expert resume writers.  回复  更多评论   

# re: POJ 1505 Copying Books 动态规划 2013-06-17 20:02 Internet site

Professional resume writers review will hint you where to buy resume paper if you are too busy to write a resume, just visit Resumes expert company resumesexpert.com, view resume writing samples and our certified resume writers will be ready to provide you best CV writing. Buying resume with us is pretty easy, buy resumes now and stay satisfied about your career.  回复  更多评论   

【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理