ZOJ 1563 Pearls

Source: Internet
Author: User

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;
}


 

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.