Topic
http://codevs.cn/problem/3162/
Title Description Description
Now to the M-Order of the book to the K-person copy (transcription), each person's transcription speed is the same, a book is not allowed to two (or more) people to copy, to each person's book, must be continuous, such as can not be the first, third, the fourth number of the same person to copy. Now, please design a scheme that will make replication time shortest. The time to copy is the number of people who have copied the most pages.
Enter a description input Description
First line two integers M, K; (k<=m<=100)
The second line is a M integer, and the first integer represents the number of pages of the book I.
Outputs description Output Description
A total of k lines, two positive integers per line, and line I indicates the starting and ending numbers of the book to be copied by the first person. The starting number of the K line should be small to large arrangement, if there are many solutions, then as far as possible to let the previous people copy less.
Sample input to sample
9 3
1 2 3 4 5 6 7 8 9
Sample output Sample Outputs
1 5
6 7
8 9
Exercises
I do not feel the division of DP a bit, the beginning of the stage and the state of the reverse ... Can still be 6 points ...
A[i the number of pages of a book] preprocessing a prefix and array w[i];
With the number of people as the stage, the number of books is the state, I personal J Book status is transferred by the state of I-1 personal p book:
F [I][J]= min J? 1 p=1 {Max{F [I?1][P],W[I]?W[P]}} ;
Initialize F[1][i]=w[i].
Output scheme, requires the front of the people to copy less pages, then let the people behind the number of pages copied, side-by-side greedy, as long as the current people to copy the page is not more than f[k][m] can.
Code
#include <cstdio>#include <algorithm>#include <cstring>#define Nusing namespace STD;intM, K, F[n][n], w[n], a[n];voidGetans (intXintY) {if(Y = =0)return;if(Y = =1) {printf("1%d\n", x);return; }intt = x; for(inti = a[x]; i + a[t-1] <= F[k][m]; --T) i + = a[t-1]; Getans (T-1, Y-1);printf("%d%d\n", t, x);}intMain () {memset(F,0x3f,sizeof(f));scanf("%d%d", &m, &k); for(inti =1; I <= m; ++i) {scanf("%d", &a[i]); f[1][i] = W[i] = a[i] + w[i-1]; } for(inti =2; I <= K; ++i) for(intj =1; J <= M; ++J) { for(intp =1; P < J; ++P) {if(F[i][j] > max (f[i-1][P], W[j]-w[p])) {F[i][j] = max (F[i-1][P], W[j]-w[p]); }}} Getans (M, k);return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The problem of Codevs3162 transcription