Click to open link
Pearls
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 7553 |
|
Accepted: 3738 |
Description
In Pearlania everybody is fond of pearls. One company, called the Royal Pearl, produces a lot of jewelry with pearls in it. The royal Pearl have 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 are much lower then the quality of pearls for the royal family. In Pearlania pearls is separated into different quality classes. A quality class is identified by the price of one single pearl in that quality class. This is the unique for, quality class and the price are always higher then the price of a pearl in a lower quality C Lass.
Every month the stock manager of the Royal Pearl prepares a list with the number of pearls needed in each quality class. The pearls is bought on the local pearl market. Each quality class have its own price per pearl, but for every complete deal in a certain quality class one have to pay an E Xtra Amount of money equal to ten pearls in the That class. 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 is more efficient. The CFO (Chief financial officer) has discovered so he can sometimes save money by buying pearls in a higher quality CLA SS than is actually needed. No customer would blame the Royal Pearl for putting better pearls in the bracelets, as long as the
Prices remain the same.
For example 5 pearls is needed in the euro category and pearls is needed in the euro category. That would normally cost: (5+10) *10+ (100+10) *20 = 2350 euro.buying All for pearls in the Euro category only costs: (5+10 0+10) *20 = 2300 Euro.
The problem is, it requires a lot of computing work before the CFO knows what many pearls can best being bought in a Highe R Quality Class. You is asked to help the Royal Pearl and a computer program.
Given a list with the number of pearls and the price per pearl in different quality classes, give the lowest possible pric E needed to buy everything on the list. Pearls can is bought in the requested,or in a higher quality class, and not in a lower one.
Input
The first line of the input contains the number of test cases. Each test case is starts with a line containing the number of categories C (1<=c<=100). Then, the C lines follow, each with the 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) is given in ascending order. All numbers in the input is integers.
Output
For each test case a single line containing a single number:the lowest possible price needed to buy everything on the LIS T.
Sample Input
22100 1100 231 101 11100 12
Sample Output
3301344
Source
Northwestern Europe 2002
give you a few kinds of different grades of pearl quantity and price, request with the least money to buy all the pearls, the total price of each pearl is (quantity +10) * unit Price, in addition can be a variety of different grades of pearls together to buy, but the unit price to calculate the largest, that is: (Quantity 1+ number of 3+...+10) * Maximum unit price.
Dp[i] represents the minimum price that is spent when buying a class I pearl, then the state transition equation is easy to come out:
Dp[i]=max (dp[i],dp[j]+ (sum[i]-sum[j]+10) *price[i]) J<=i Dp[j] represents the minimum price that is spent when buying a class J Pearl, Sum[i] represents all the quantities of the former Class I pearls and, sum[i]- SUM[J] represents the sum of pearls of these grades from J to I.
3880#include<stdio.h> #include <string.h> #include <algorithm> #define INF 0x3f3f3f3fusing namespace std;struct pearls{ int a,p;} Pearl[1007];int Dp[1007],sum[1007];int Main () { int t,n; scanf ("%d", &t); while (t--) {for (int i=1;i<=100;i++) dp[i]=inf;//initialize dp[0]=0; memset (sum,0,sizeof (sum)); scanf ("%d", &n); for (int i=1;i<=n;i++) scanf ("%d%d", &PEARL[I].A,&PEARL[I].P); for (int i=1;i<=n;i++)//Cumulative commodity quantity sum[i]=sum[i-1]+pearl[i].a; dp[1]= (pearl[1].a+10) *pearl[1].p; for (int. i=2;i<=n;i++) for (int j=0;j<=i;j++)//enumeration J to i these grade pearls buy together the situation Dp[i]=min (dp[i],dp[j]+ (sum[i]- SUM[J]+10) *PEARL[I].P); printf ("%d\n", Dp[n]); } return 0;}
POJ 1260 Pearls ~\ (≧▽≦)/~