HDU 1300 Pearls (DP)

Source: Internet
Author: User

Pearls

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 2018 Accepted Submission (s): 953

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 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 pearls in the euro category only costs: (5+100+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.

Inputthe 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.

Outputfor each test case a single line containing a single number:the lowest possible price needed to buy everything on t He list.

Sample Input22100 1100 231 101 11100 12

Sample Output3301344

Sourcenorthwestern Europe 2002

1 /*Test Instructions: There are n kinds of jewels, each piece of jewelry has to buy the quantity of AI and the unit price of pi,c jewelry increases. 2 If you buy some kind of jewelry, you need to pay an extra 10*pi fee (supposedly to prevent you from buying only one ...). ),3 at the same time can buy the same number of high-priced jewelry instead of low-priced jewelry, which may save some money. 4 The minimum cost required to buy the required jewellery. 5 */6 7 /*8 idea: Dp[i] represents the minimum cost of the pre-purchase I pearls, the interval of enumeration instead9 */ Ten  One #pragmaComment (linker, "/stack:1024000000,1024000000") A#include <iostream> -#include <cstdio> -#include <cstring> the#include <cmath> -#include <math.h> -#include <algorithm> -#include <queue> +#include <Set> -#include <bitset> +#include <map> A#include <vector> at#include <stdlib.h> - using namespacestd; - #definell Long Long - #defineEPS 1e-10 - #defineMOD 1000000007 - #defineN 106 in #defineINF 1<<29 - intN; to intNum[n],val[n]; + intDp[n];//Dp[i] Indicates the minimum value that was spent when I was selected - intMain () the { *     intT; $scanf"%d",&t);Panax Notoginseng      while(t--){ -scanf"%d",&n); the          for(intI=1; i<=n;i++){ +scanf"%d%d",&num[i],&val[i]); A         } the          for(intI=1; i<=n;i++){ +Dp[i]=inf;//At the beginning the value of the INF opened, WA several times -         } $dp[0]=0;//Dp[0] must be 0 $dp[1]= (num[1]+Ten) *val[1]; -          for(intI=2; i<=n;i++){ -              for(intj=1; j<=i;j++){ the                 intres=dp[j-1]; -                 intCnt=0;Wuyi                  for(intk=j;k<=i;k++){ thecnt+=Num[k]; -                 } Wures+= (cnt+Ten)*Val[i]; -dp[i]=min (dp[i],res); About             } $         } -printf"%d\n", Dp[n]); -     } -     return 0; A}

HDU 1300 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.