UVALive 6424 Russian Dolls
来源:互联网 发布:淘宝上传宝贝图片大小 编辑:程序博客网 时间:2024/06/08 22:11
6424 Russian Dolls
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
The input file contains several test cases, each of them as described below. 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.
Sample Output
For each test case, write to the output a single integer P which is the minimum possible cost you should pay on a line by itself.
Sample Input
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
The input file contains several test cases, each of them as described below. 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.
Sample Output
For each test case, write to the output a single integer P which is the minimum possible cost you should pay on a line by itself.
Sample Input
3
5 4 1
4 2 2
3 2 1
Sample Output7
一开始没有想到是贪心,还以为是动规,没仔细想清楚Orz
每个套娃有一个外体积和一个内体积还有一个单位空闲空间的花费
嵌套可以减小花费,故按花费降序排列,内含可容下的最大体积的套娃
每个内含的套娃标记为用过
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct Doll{int out, in, cost;bool operator < (const Doll &A)const{return cost > A.cost;}//降序}d[1005];int n,sum;bool used[1010];int main(){while(cin>>n) {sum = 0; memset(used,0,sizeof(used));for(int i=0; i<n; i++){cin>>d[i].out>>d[i].in>>d[i].cost;sum += d[i].cost * d[i].in;used[i] = 0;}sort(d, d+n);int x;for(int i=0; i<n; i++){x = -1;for(int j=0; j<n; j++){if(!used[j] && d[j].out<d[i].in){if(x==-1 || d[j].out>d[x].out) x=j;}}if(x!=-1){sum -= d[x].out * d[i].cost;used[x] = 1;}}cout<<sum<<endl;}return 0;}
0 0
- UVALive 6424 Russian Dolls
- UVALive 6424 Russian Dolls(贪心)
- UVALive 6424 Russian Dolls 贪心
- UVALive 6424 Russian Dolls 贪心
- Uvalive 6424 - Russian Dolls (贪心)
- UVALive 6424 —— Russian Dolls(贪心)
- 文章标题UVALive 6424:Russian Dolls(贪心)
- 6424 Russian Dolls--贪心
- Russian Dolls
- Russian Dolls
- uva 10549 Russian Dolls (DP)
- POJ 2303 Russian Dolls 笔记
- today russian
- Nested Dolls
- poj_3636Nested Dolls
- Nested Dolls
- HDU4160--Dolls
- POJ3636Nested Dolls
- 如何为第三方提供一个jar包
- C#中,当鼠标移动到控件上,动态显示提示内容 ToolTip
- ROS学习笔记(1)-----ROS Kinetic版本安装
- 使用Gradle管理你的Android Studio工程
- 【数据结构】图论算法笔记整理
- UVALive 6424 Russian Dolls
- 孙鑫《VC++深入详解》完整版PDF 下载
- 完整的node项目
- mysql数据库日期设计以及mybatis映射文件和实体属性的关系
- ios 代码块的妙用
- php如何通过无限极分类创建文件夹并纯静态分类下的内容
- python2.7,Ubuntu14.04环境下pip安装插件,cffi插件出现一下错误解决办法。
- 【Android】首次进入应用时加载引导界面
- ViewFlipper的使用例子