Question: a jewelry store buys pearls from a pearl wholesaler. The I-price is P [I]. The price of the pearl is Σ (n + 10) * P [I] because the number of unplanted pearls must be increased by 10 during settlement, sometimes the price of cheap pearls is reduced by the price of expensive settlement. For you, the price of a pearl in a purchase list is increasing progressively. pearl can be replaced with the minimum total cost that is more expensive than it.
Simple DP order d [I] represents the minimum cost of the first I Pearl sum [I] represents the total number of the first I to the first I, then there is a transfer equation d [I] = min {d [J-1] + (sum [I]-sum [J-1] + 10) * P [I]} (sum [I]-sum [J-1] + 10) * P [I] indicates that all the pearls from the J to the I are replaced with the I
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N = 105;int p[N], d[N], s[N],num, n, cas;int main(){ scanf ("%d", &cas); while (cas--) { scanf ("%d", &n); for (int i = 1; i <= n; ++i) { scanf ("%d%d", &num, &p[i]); s[i] = s[i - 1] + num; } memset(d,0x3f,sizeof(d)); d[0]=0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) d[i] = min (d[i], d[j-1] + (s[i] - s[j - 1] + 10) * p[i]); printf ("%d\n", d[n]); } return 0;}
Pearls
Problem descriptionin pearlania everybody is fond of pearls. one company, called the royal Pearl, produces a lot of jewelry with pearls in it. the Royal Pearl has its name because it delivers to the royal family of pearlania. but it also produces bracelets and necklaces for ordinary people. of course the quality of the pearls for these people is much lower then the quality of pearls for the royal family. in pearlania pearls are separated into 100 different quality classes. A quality class is identified by the price for one single pearl in that quality class. this price is unique for that quality class and the price is always higher then the price for a pearl in a lower quality class.
Every month the stock manager of the Royal Pearl prepares a list with the number of pearls needed in each quality class. the pearls are bought on the local pearl market. each quality class has its own price per Pearl, but for every complete deal in a certain quality class one has to pay an extra amount of money equal to ten pearls in that class. this is to prevent tourists from buying just one pearl.
Also the royal pearl is suffering from the slow-down of the global economy. therefore the company needs to be more efficient. the CFO (Chief Financial Officer) has discovered that he can sometimes save money by buying pearls in a higher quality class than is actually needed. no customer will blame the royal Pearl for putting better pearls in the bracelets, as long as the prices remain the same.
For example 5 pearls are needed in the 10 Euro category and 100 pearls are needed in the 20 Euro category. that will normally cost: (5 + 10) * 10 + (100 + 10) * 20 = 2350 Euro.
Buying all 105 pearls in the 20 Euro category only costs: (5 + 100 + 10) * 20 = 2300 Euro.
The problem is that it requires a lot of computing work before the CFO knows how can pearls can best be bought in a higher quality class. you are asked to help the royal Pearl with a computer program.
Given a list with the number of pearls and the price per pearl in different quality classes, give the lowest possible price needed to buy everything on the list. pearls can be bought in the requested, or in a higher quality class, but not in a lower one.
Inputthe first line of the input contains the number of test cases. each test case starts with a line containing the number of categories C (1 <= C <= 100 ). then, C lines follow, each with two numbers AI and PI. the first of these numbers is the number of pearls AI needed in a class (1 <= AI <= 1000 ). the second number is the price per Pearl PI in that class (1 <= pI <= 1000 ). the qualities of the classes (and so the prices) are given in ascending order. all numbers in the input are integers.
Outputfor each test case a single line containing a single number: the lowest possible price needed to buy everything on the list.
Sample Input
22100 1100 231 101 11100 12
Sample output
3301344