POJ 1260.Pearls

Source: Internet
Author: User

Pearls Time limit:1000MS Memory Limit:10000KB 64bit IO Format:%i64d &%i64 U Submit Status Practice POJ 1260

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
Using dp[i] means the minimum amount of money needed to buy the first I pearls according to the greedy, buy the first I kind of pearls, buy more The more cost-effective. That is, for the pearl of the first I, either do not buy, or the front of the cheaper not to buy and the group to buy all bought so, for each layer, only buy and do not buy two options and can not appear cheap not buy but expensive bought dp[i]= min{dp[i-1] + (Num[i] + ten) *price[i], Dp[j] + (Sum[i]-sum[j] + ten) *price[i]} 0<=j<iThe first part is the case that each group buys, the latter part is the case that j~i not buy do not use sort order, will WA. In the order of input, regardless of the price from small to large input AC code: GITHUB
1 /*2 By:ohyee3 Github:ohyee4 Homepage:http://www.oyohyee.com5 Email:[email protected]6 Blog:http://www.cnblogs.com/ohyee/7 8 かしこいかわいい? 9 エリーチカ! Ten to write out the хорошо code OH ~ One */ A  -  -#include <cstdio> the#include <algorithm> -#include <cstring> -#include <cmath> -#include <string> +#include <iostream> -#include <vector> +#include <list> A#include <queue> at#include <stack> -#include <map> - using namespacestd; -  - //DEBUG MODE - #defineDebug 0 in  - //Loops to #defineREP (n) for (int o=0;o<n;o++) +  - /* the Test instructions Understand: * Pearls have different prices and need to buy a certain number of pearls at a specified price $ for a price to buy pearls, you need to pay 10 of the price of such a pearl feePanax Notoginseng you can replace poor pearls with better jewelry. -  the find out the minimum price that is spent + */ AtypedefintLL; the  + Const intMAXN = the; -  $ structPearl { $     intnum; -     intPrice ; -     BOOL operator< (ConstPearl &AMP;RHS)Const { the         returnPrice <Rhs.price; -     }Wuyi }; the  - Pearl P[MAXN]; Wu  - //minimum value required to buy the first I-Type pearls About LL DP[MAXN]; $  - intM[MAXN]; -  - voidDo () { A     intN; +scanf"%d",&n); them[0] =0; - REP (n) $scanf"%d%d", &p[o +1].num,&p[o +1].price); theMemset (DP,0,sizeof(DP)); the     //Sort (p + 1,p + 1 + N); the REP (n) theM[o +1] = M[o] + p[o+1].num; -  in      for(inti =1; I <= n;i++) { theDp[i] = dp[i-1] + (P[i].num +Ten) *P[i].price; the          for(intj =0; J < i;j++) AboutDp[i] = min (Dp[i],dp[j] + (LL) (M[i]-m[j] +Ten) *p[i].price); the     } theprintf"%d\n", Dp[n]); the  +     return; - } the Bayi intMain () { the     intT; thescanf"%d",&T); -      while(t--) - Do (); the     return 0; the}

POJ 1260.Pearls

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.