POJ 1260 Pearls (DP)

Source: Internet
Author: User

Pearls
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 7946 Accepted: 3948

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


Test Instructions: There are n kinds of pearls, the quality of the pearl in accordance with the input order from small to large arrangement, each has to buy the number, need to pay the Price = (the number of pearls to buy + 10) * The price of the Pearl, wherein the quality of the pearl can be used to replace the quality of pearls, to do so to pay the minimum


#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Stdlib.h> #define INF 9999#define inf-9999using namespace Std;int n,m;int a[110],b[110];int sum[110];int dp[110];int m Ain () {    int T;    scanf ("%d", &t);    while (t--)    {        scanf ("%d", &n);        Sum[0] = 0;        for (int i=1;i<=n;i++)        {            scanf ("%d%d", &a[i],&b[i]);            Sum[i] = Sum[i-1] + a[i];        }        Dp[0] = 0;        for (int i=1;i<=n;i++)        {            Dp[i] = dp[i-1] + (A[I]+10) *b[i];            for (int j=0;j<=i;j++)            {                Dp[i] = min (Dp[i], (((Sum[i]-sum[j]) +10) *b[i]+dp[j]));            }        }        printf ("%d\n", Dp[n]);    }    return 0;}


Copyright NOTICE: This article is the original blogger article, if you have special needs, please contact Bo Master qq:793977586.

POJ 1260 Pearls (DP)

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.