Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:65536KB |
Total submit users: 12, Accepted users: 9 |
Problem 12895 : No special judgement |
Problem description |
Maybe you know the famous russian souvenir Russian Dolls. It looks like a set of nested wooden dolls. A doll with a smaller size is placed inside a bigger one. Let's consider all dolls taken apart. Each doll has an outer volume outi which is the volume it
occupies in space and an inner volume ini - the volume of the empty space inside the doll. You may assume that you can put one doll inside another if the outer volume of the first doll is strictly less than the inner volume of the second one. If two or more
dolls are inside another one they can't lie one near the other, they must be nested. |
Input |
First line contains an integer N (1 ≤ N ≤ 1000) which is the number of dolls you have. The i-th of the next N lines contains three integers outi, ini, costi (1 ≤ ini < outi ≤ 1000, 1 ≤ costi ≤ 1000), which are the outer volume, inner volume and the empty space cost of the i-th doll. |
Output |
Single integer P which is the minimum possible cost you should pay. |
Sample Input |
3 5 4 1 4 2 2 3 2 1 |
Sample Output |
7 |
#include<iostream>
#include<cstring>//一個是思路問題,一個是要是升序問題,一個是排序後它會變序,要新建一個數組排序
#include<cstdio>
#include<algorithm>//求最大值時別忘了改值
#define inf 999999
#define maxn 1010
using namespace std;
int outi[maxn];
int ini[maxn];
struct node
{
int out,in,cos;
}str[maxn];
bool v[maxn];
int temp[maxn];
bool cmpa(int a,int b)
{
return str[a].out>str[b].out;
}
bool cmpb(int a,int b)//這是升序吧
{
if(str[a].in==str[b].in)
return str[a].cos>str[b].cos;
return str[a].in>str[b].in;
}
int main()//break,初始化
{
int T;
while(scanf("%d",&T)!=EOF)
{
for(int i=1;i<=T;i++)
{
cin>>str[i].out>>str[i].in>>str[i].cos;
ini[i]=i;outi[i]=i;
}
sort(outi+1,outi+T+1,cmpa);//排序問題,升序
sort(ini+1,ini+T+1,cmpb);
int ans=0;
memset(v,0,sizeof(v));
for(int i=1;i<=T;i++)
{
int x=0;
for(int j=1;j<=T;j++)
{
if(str[outi[i]].out<str[ini[j]].in&&!v[ini[j]])
temp[++x]=ini[j];
}
//cout<<x<<endl;
if(x>=1)
{
int vmax=0;
int res;
for(int k=1;k<=x;k++)
{
int tep=str[temp[k]].cos*str[outi[i]].out;//減的量
//cout<<tep<<endl;
if(vmax<tep)
{
vmax=tep;
res=temp[k];//這裏一開始忘了改值
}
}
v[res]=1;
//cout<<res<<endl;
ans+=str[res].cos*str[outi[i]].out;
}
}
int result=0;
for(int i=1;i<=T;i++)
{
result+=str[i].cos*str[i].in;
}
result-=ans;
//cout<<ans<<endl;
cout<<result<<endl;
}
}