Pearls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1860 Accepted Submission(s): 868
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.
2 2 100 1 100 2 3 1 10 1 11 100 12
330 1344
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
#define eps 1e-8
#define INF 0x3f3f3f3f
typedef __int64 ll;
using namespace std;
#define INF 0x3f3f3f3f
#define N 205
int n,num[N],p[N];
int sum[N];
int dp[N];
void DP()
{
int i,j;
memset(dp,INF,sizeof(dp));
dp[0]=0;
for(i=1;i<=n;i++)
{
for(j=0;j<i;j++)
dp[i]=min(dp[i],dp[j]+(sum[i]-sum[j]+10)*p[i]);//枚举当前状态可以由哪些状态而来
}
printf("%d\n",dp[n]);
}
int main()
{
int i,j,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d",&num[i],&p[i]);
sum[i]=sum[i-1]+num[i];
}
DP();
}
return 0;
}
1万+



被折叠的 条评论
为什么被折叠?



