poj1260--Linear DP

Source: Internet
Author: User

poj1260--Linear Dppearls
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 7705 Accepted: 3811

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
Test instructions: To buy pearls of some value, but to buy a certain pearl must pay more than 10 of the price of such pearls, and if the purchase value of 1 pearls 100, must pay 110. A pearl can be sucks than its expensive pearls, so it may be cheaper to buy a variety of pearls with expensive alternatives. For example, buy 100 value for 2, 1 value for 1, at this time buy 101 value of 2 for the better program. Enter the number of pearls you want to buy, using the high-priced pearl sucks, asking at least how much money to spend.
Note: The price of the topic has been given in ascending order
Idea: Dp[i]=min (dp[i],dp[j]+ (a[j+1]+a[j+2]+...+a[i]+10) *p[i]) =min (dp[i],dp[j]+ (sum[i]-sum[j]+10) *p[i])
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespacestd;Const intmaxn=1000100;Const intInf= (1<< -);intT;intC;intA[MAXN],P[MAXN];intDP[MAXN];intSUM[MAXN];intMain () {CIN>>u;  while(t--) {cin>>C; a[0]=0;  for(intI=1; i<=c;i++) {cin>>a[i]>>P[i]; Sum[i]=sum[i-1]+A[i]; } dp[0]=0;  for(intI=1; i<=c;i++) dp[i]=INF;  for(intI=1; i<=c;i++){             for(intj=0; j<i;j++) {Dp[i]=min (dp[i],dp[j]+ (sum[i]-sum[j]+Ten)*P[i]); }} cout<<dp[c]<<Endl; }    return 0;}
View Code

poj1260--Linear 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.