/* Sort... water ..
*
* Try the following rent data for WA:
* 1
* 2 11 16
* 2
* 2 11 16
* 2 1 3
* The output should be
* Workyards 1
* Maximum profit is 0.
* Number of pruls to buy: 0
*
* Workyards 2
* Maximum profit is 16.
* Number of pruls to buy: 2
* When the maximum profit is less than 0, merchants will not buy items in the heap if the maximum profit is less than 0, that is, the maximum profit in the heap should be 0, instead of the negative number obtained.
*
*/
# Include <cstdio>
# Include <cstdlib>
# Include <cstring>
Using namespace STD;
Const int maxw = 50 + 5;
Const int maxb = 20 + 5;
Int W, B [maxw], data [maxw] [maxb]; // input data
Int P [maxw] [maxb], num [maxw] [maxb], IMAX [maxw], K [maxw];
// P [I] [J]: The profit of buying J in group I... num [I] [J]: the maximum number of purchased products in group I... IMAX [I]: Maximum Profit of group I... K [I]: upper bound of num [I]
Int ans_max, ANS [10000], T; // ans_max: maximum profit... Ans []: number of purchases .... T: upper bound of ANS
Void INI (){
Memset (p, 0, sizeof (p ));
Memset (IMAX, 0, sizeof (IMAX ));
Memset (K, 0, sizeof (k ));
Memset (Num, 0, sizeof (Num ));
T = 0, ans_max = 0;
}
Void DFS (int I, int last_v ){
If (I = W + 1 ){
Ans [t ++] = last_v;
Return;
}
If (IMAX [I] = 0) DFS (I + 1, last_v );
For (INT q = 1; q <= K [I]; q ++ ){
DFS (I + 1, last_v + num [I] [Q]);
}
}
Int CMP (const void * a, const void * B ){
Return * (int *) A-* (int *) B;
}
Int main (){
Int tot = 0;
While (scanf ("% d", & W )){
If (W = 0) return 0;
TOT ++;
INI ();
For (INT I = 1; I <= W; I ++ ){
Scanf ("% d", & B [I]);
For (Int J = 1; j <= B [I]; j ++ ){
Scanf ("% d", & Data [I] [J]);
P [I] [J] = P [I] [J-1] + 10-data [I] [J];
If (IMAX [I] <p [I] [J]) Imax [I] = P [I] [J];
}
}
For (INT I = 1; I <= W; I ++ ){
For (Int J = 1; j <= B [I]; j ++ ){
If (P [I] [J] = IMAX [I])
Num [I] [++ K [I] = J;
}
Ans_max + = IMAX [I];
}
DFS (1, 0 );
Qsort (ANS, T, sizeof (INT), CMP );
Printf ("workyards % d \ nmaximum profit is % d. \ n", TOT, ans_max );
Printf ("Number of pruls to buy :");
Int I = 0, j = 0;
For (; j <10-1 & I <T-1; I ++ ){
If (I = 0 | (I! = 0 & Ans [I]! = Ans [I-1]) {
Printf ("% d", ANS [I]);
J ++;
}
}
For (; I <t; I ++ ){
If (I = 0 | (I! = 0 & Ans [I]! = Ans [I-1]) {
Printf ("% d \ n", ANS [I]);
Break;
}
}
}
Return 0;
}
Loading editor...