POJ 1260 Pearls(DP)
4296 단어 dp
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 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 many 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.
Input
The 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.
Output
For each test case a single line containing a single number: the lowest possible price needed to buy everything on the list.
Sample Input
2
2
100 1
100 2
3
1 10
1 11
100 12
Sample Output
330
1344
제목의 뜻: 서로 다른 진주의 수량과 가격을 정한다(물론 가격은 고품질이면 된다).진주의 질을 낮추지 않는 한 구입한 진주의 비용을 최소화해 주십시오.
진주를 구매하는 데는 두 가지 방안이 있다. 예를 들어 테스트 데이터 1:(100+10)*1+(100+10)*2=330을 직접 구매한다.또는 (100+100+10)*2=420;그래서 방안을 선택한다.
사고방식: 우리는 먼저 직접 구매하는 방식으로 모든 진주를 구매할 수 있으며 서로 다른 단계의 비용은ans[i]에 존재한다.그리고 현재 ans[i]의 값과 저의 두 번째 구매 비용의 비교를 열거하고 택민은 ans[]에 저장합니다.
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
int num[110],p[110],sum[110],ans[110];
int dp[600];
int main()
{
int n,m,x,k,i,j;
int cla;
scanf("%d",&cla);
while(cla--)
{
scanf("%d",&n);
sum[0]=0;
for(i=1;i<=n;i++)
{
scanf("%d%d",&num[i],&p[i]);
sum[i]=sum[i-1]+num[i];//
ans[i]=p[i]*(10+sum[i]);//
}
for(i=1;i<=n;i++)
for(j=1;j<i;j++)
if(p[j]<p[i])//
if(ans[i]>ans[j]+(sum[i]-sum[j]+10)*p[i])
ans[i]=ans[j]+(sum[i]-sum[j]+10)*p[i];
printf("%d
",ans[n]);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【경쟁 프로 전형적인 90문】008의 해설(python)의 해설 기사입니다. 해설의 이미지를 봐도 모르는 (이해력이 부족한) 것이 많이 있었으므로, 나중에 다시 풀었을 때에 확인할 수 있도록 정리했습니다. ※순차적으로, 모든 문제의 해설 기사를 들어갈 예정입니다. 문자열...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.