HDU 1300 pearls

Source: Internet
Author: User
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
According to the constraints, replacement must be continuous. DP [I] = min {DP [J] + V}, 0 <= j <I, V is the value of Category J + 1 jewelry to category I which is bought in class I;
#include <stdio.h>int t,n,nums[1001],opt[1001];int main(){scanf("%d",&t);opt[0] = 0;int sum,tmpMin,p;while(t--){scanf("%d", &n);for(int i=1; i<=n; i++){scanf("%d %d",&nums[i], &p);sum = 0;tmpMin = 100000000;for(int j=i; j>0; j--){sum += nums[j];int t = (sum + 10) * p + opt[j-1];if(tmpMin > t)tmpMin = t;}opt[i] = tmpMin;}printf("%d\n",opt[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.