POJ1505 Copying Books (dichotomy)

Source: Internet
Author: User

B-Two pointsTime limit:3000MS Memory Limit:0KB 64bit IO Format:%lld &%llu  

Description

Before the invention of book-printing, it is very hard-make a copy of a book. All of the contents had to is re-written by hand and calledscribers. 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 its name was Xaverius endricus Remius Ontius Xendrianus ( xerox). Anyway, the work is very annoying and boring. And the only-to-speed it up is to hire more scribers.


Once upon a time, there was a theater ensemble the 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 havemBooks (numbered) the May has different number of pages () and want to make one copy of each of the them. Your task is to divide these books amongkScribes,. Each book can is assigned to a scriber only, and every scriber must get a continuous sequence of books. That is means, there exists an increasing succession of numbers such thatI-th Scriber gets a sequence of books with numbers betweenbI-1+1 andbI. The time needed to make a copy of the "All the books are determined by the" the Scriber who were assigned the most work. Therefore, our goal are 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-lines. At the first line, there is integers m and K,. At the second line, there is integers separated by spaces. All these values is positive and less than 10000000.

Output

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


If there is more than one solution, print the one of the minimizes the work assigned to the first Scriber and then the Secon D Scriber etc. But each scriber must is assigned at least one book.

Sample Input
29 3100 200 300 400 500 600 700 800 9005 4100 100 100 100 100

Sample Output
100 200 300 400 500/600 700/800 900100/100/100/100 100

Puzzle: The maximum value is as small as possible, so that a sequence containing m positive integers is divided into K non-empty continuous sub-sequences, and each positive integer belongs exactly to a subsequence. Set the sum of each number of the sequence I is S (i), so that the maximum value of s (i) is as small as possible.

Each integer must not exceed 10 of the 7-square, if there are many solutions, s (1) should be as small as possible, if there are still many solutions, S (2) should be as small as possible, and so on.

The key to solving the problem is to find a limit value, all of S (i) are not more than X, from right to left, the range of this x (the largest value in the sequence ~ sequence of all values)

AC Code:

#include <iostream>#include<cstring>using namespacestd;intm,k;intb[502],f[502];Long LongTotal ;intJuge (Long Longx) { Total=1; Long Longsum=0; Memset (F,0,sizeof(f));  for(inti=m-1; i>=0; i--) {sum+=B[i]; if(sum>x) { Total++; Sum=B[i]; F[i]=1; }    }    returnTotal ;}intMain () {intT; Long Longr,l; CIN>>T;  while(t--) {cin>>m>>K; L=r=0;  for(intI=0; i<m; i++) {cin>>B[i]; if(b[i]>l) {L=b[i];//The limit value is from the maximum value of the sequence to all values in the sequence and between} R+=B[i]; }         while(l<r) {intMid= (L+R)/2; if(Juge (mid) <=k) R=mid; ElseL=mid+1; }        intTotal=juge (R); //cout<<r; //The output of the limit values, such as over here, the basic is over         for(intI=0; i<m;i++)        {            if(total<k)if(!F[i]) {F[i]=1; Total++; }} cout<<b[0];  for(intI=1;i<m; i++)            {                if(f[i-1]) cout<<" /"; cout<<' '<<B[i]; } cout<<Endl; }        return 0; }

POJ1505 Copying Books (dichotomy)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.