PID496/[IOI1999] Flower shop window Layout ☆
Title Description
A flower shop existing F bouquet, each bouquet of flowers are different, at the same time at least the same number of vases, are placed in the order of a row, the position of the vase is fixed, from left to right by 1 to v sequential numbering, V is the number of vases. The bouquet can be moved, and each bouquet is identified by an integer of 1 to F. If I < J, the bouquet I must be placed in the vase to the left of the Bouquet J. For example, suppose the number of the Rhododendron is 1, Begonia's identification number is 2, carnation identification number is 3, all bouquets must keep its identification number in the order of the flower vase, that is, the rhododendron must be placed on the left side of Begonia, Begonia must be placed in the vase on the left of the carnation. If the number of vases is greater than the number of bouquets, the extra vase must be empty, that is, each vase can only put a bouquet of flowers.
Each vase has a different shape and color, so when each vase is placed in a different bouquet, the aesthetic effect is varied and is expressed as an aesthetic value (an integer), and the aesthetic value of the vacant vase is 0. In the above example, the aesthetic values of the different combinations of vases and bouquets can be expressed in the following table:
Vase 1 Vase 2 Vase 3 vase 4 vase 5
Rhododendron 7 23-5-24 16
Begonia 5 21-4 10 23
Carnation-21 5-4-20 20
According to the table, the Rhododendron in the Vase 2 will look very good, but if placed in the Vase 4, it looks very difficult to see.
In order to achieve the best aesthetic effect, the flower must be placed in order to achieve the maximum aesthetic value, if there is a maximum aesthetic value of the placement of more than one way, then the output of any one solution.
Input Format
The first line of the input file is two integers F and V, respectively, bouquet number and vase number (1≤f≤100,f≤v≤100). Next is the matrix AIJ, which has an I row, j integers per line, and AIJ represents the aesthetic value of the bouquet I placed in the Vase J.
output Format
The first line of the output file is an integer, which is the maximum aesthetic value; Next there is an F line, two numbers per line, and a number for that bouquet of flowers into that vase.
Sample input
3 5
7 23-5-24 16
5 21-4 10 23
-21 5-4-20 20
Sample output
53
2 4 5
Solving:.... Dynamic planning
1#include <iostream>2#include <cstdio>3#include <cstring>4 #defineINF 0x3f3f3f3f5 using namespacestd;6 Const intMAXN = $;7 intdp[maxn][maxn],d[maxn][maxn],p[maxn][maxn],n,m;8 intMain () {9 while(~SCANF ("%d%d",&n,&m)) {TenMemset (DP, -,sizeof(DP)); One for(inti =0; I <= m; ++i) dp[0][i] =0; A - for(inti =1; I <= N; ++i) - for(intj =1; J <= M; ++j) thescanf"%d",&d[i][j]); - - for(inti =1; I <= N; ++i) { - for(intj = i; J <= M; ++j) { + for(intK = i; K <= J; ++k) { - if(dp[i-1][k-1] + D[i][k] >Dp[i][j]) { +DP[I][J] = dp[i-1][k-1] +D[i][k]; AP[I][J] =K; at } - } - } - } - intIDX = P[n][m],res[maxn],tot =0; -printf"%d\n", Dp[n][m]); in for(inti = n; i >0; --i) { -Res[++tot] =idx; toIDX = p[i-1][idx-1]; + } - for(inti = tot; i >0; --i) theprintf"%d%c", Res[i],i = =1?'\ n':' '); * } $ return 0;Panax Notoginseng } - /* the 3 5 + 7 23-5 -24 A 5 21-4 the -21 5-4 -20 + */
View Code
Rqnoj pid496/[ioi1999] Flower shop window layout