Meaning: I haven't understood it for a long time ......
There are different quality pearls, and the price of high-quality pearls is higher than that of low quality pearls.
Purchase quantity a for each quality Pearl and the unit price for this quality Pearl.
Price Calculation Method: (quantity purchased + 10) × Unit Price
Low quality pearls can be replaced by high-quality pearls.
Enumerative j. These quality pearls from j to I are replaced by the I Pearl.
State transition equation: F (I) = min (F (I), F (J-1) + (sum (j, I) + 10) * p (I ))
Sum (j, I) is the total number of quality pearls from j to I.
# Include <cstdio>
# Include <cstring>
Using namespace std;
# Define N 110
# Define inf 0x3f3f3f
Int a [N], p [N], n;
Int f [N];
Int main (){
Int T;
Scanf ("% d", & T );
While (T --){
Memset (f, 0x3f, sizeof (f ));
F [0] = 0;
Scanf ("% d", & n );
For (int I = 1; I <= n; I ++) scanf ("% d", & a [I], & p [I]);
For (int I = 1; I <= n; I ++ ){
Int sum = 10;
For (int j = I; j> 0; j --){
Sum + = a [j];
If (f [I]> f [J-1] + sum * p [I])
F [I] = f [J-1] + sum * p [I];
}
}
Printf ("% d \ n", f [n]);
}
Return 0;
}