Russian Dolls

本文深入探讨了深度学习在人工智能领域的应用,包括神经网络、机器学习算法及其在图像处理、自然语言处理和强化学习等领域的实践案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

For each doll the cost of unit of empty space - costi is known. You must pay exactly costi for each unit of empty space which directly belongs to the i-th doll (but not to ones inside it). You may arrange the dolls the way you want as long as you are not contradicting the rules. The objective is to find an arrangement of nesting the dolls (not necessarily all of them) such that the overall cost you have to pay is minimized.


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;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值