To Miss Our Children Time

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 4502    Accepted Submission(s): 1224

Problem Description
Do you remember our children time? When we are children, we are interesting in almost everything around ourselves. A little thing or a simple game will brings us lots of happy time! LLL is a nostalgic boy, now he grows up. In the dead of night, he often misses something, including a simple game which brings him much happy when he was child. Here are the game rules: There lies many blocks on the ground, little LLL wants build "Skyscraper" using these blocks. There are three kinds of blocks signed by an integer d. We describe each block's shape is Cuboid using four integers ai, bi, ci, di. ai, bi are two edges of the block one of them is length the other is width. ci is 
thickness of the block. We know that the ci must be vertical with earth ground. di describe the kind of the block. When di = 0 the block's length and width must be more or equal to the block's length and width which lies under the block. When di = 1 the block's length and width must be more or equal to the block's length which lies under the block and width and the block's area must be more than the block's area which lies under the block. When di = 2 the block length and width must be more than the block's length and width which lies under the block. Here are some blocks. Can you know what's the highest "Skyscraper" can be build using these blocks?
 
Input
The input has many test cases. 
For each test case the first line is a integer n ( 0< n <= 1000) , the number of blocks. 
From the second to the n+1'th lines , each line describing the i‐1'th block's a,b,c,d (1 =< ai,bi,ci <= 10^8 , d = 0 or 1 or 2). 
The input end with n = 0.
 
Output
Output a line contains a integer describing the highest "Skyscraper"'s height using the n blocks.
 
Sample Input
3
10 10 12 0
10 10 12 1
10 10 11 2
2
10 10 11 1
10 10 11 1
0
 
Sample Output
24
11
 
Source
题解:当时没细想,就是个很水的dp。。。1000两重for,注意long long;
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN = ;
typedef long long LL;
struct Node{
int w, h, c, d;
void init(){
scanf("%d%d%d%d", &w, &h, &c, &d);
if(w > h){
swap(w, h);
}
}
friend bool operator < (Node a, Node b){
if(a.h != b.h)
return a.h < b.h;
if(a.w != b.w)
return a.w < b.w;
return a.d > b.d;
}
};
Node dt[MAXN];
LL dp[MAXN];
bool js(Node a, Node b){
if(b.d == && a.w < b.w && a.h < b.h)
return true;
else if(b.d == && a.w <= b.w && a.h <= b.h && (a.w < b.w || a.h < b.h))
return true;
else if(b.d == && a.w <= b.w && a.h <= b.h)
return true;
return false;
}
int main(){
int n;
while(~scanf("%d", &n), n){
for(int i = ; i < n; i++){
dt[i].init();
}
sort(dt, dt + n);
memset(dp, , sizeof(dp));
LL ans = ;
for(int i = ; i < n; i++){
dp[i] = dt[i].c;
for(int j = ; j < i; j++){
if(js(dt[j], dt[i]))
dp[i] = max(dp[i], dp[j] + dt[i].c);
}
ans = max(ans, dp[i]);
}
printf("%lld\n", ans);
}
return ;
}

To Miss Our Children Time(dp)的更多相关文章

  1. 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)

    暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(S ...

  2. WPF制作QQ列表(仿qq列表特效)

    先看效果图:这个是折叠特效. 代码结构:      model是我们的数据模型,定义了在列表显示的人物名称   图片   简介    . Resource是我们的图片资源  和 存储图片资源路径.名称 ...

  3. CF1249F Maximum Weight Subset

    CF1249F Maximum Weight Subset 洛谷评测传送门 题目描述 You are given a tree, which consists of nn vertices. Reca ...

  4. hdu 4001 To Miss Our Children Time( sort + DP )

    To Miss Our Children Time Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Jav ...

  5. HDU 4001 To Miss Our Children Time(2011年大连网络赛 A 贪心+dp)

    开始还觉得是贪心呢... 给你三类积木叫你叠楼房,给你的每个积木包括四个值:长 宽(可以互换) 高 类型d d=0:你只能把它放在地上或者放在 长 宽 小于等于 自己的积木上面 d=1:你只能把它放在 ...

  6. hdu 4960 Another OCD Patient(dp)

    Another OCD Patient Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Ot ...

  7. POJ3107Godfather[树形DP 树的重心]

    Godfather Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6121   Accepted: 2164 Descrip ...

  8. codeforces 484D D. Kindergarten(dp)

    题目链接: D. Kindergarten time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. 积木(DP)问题

    问题:Do you remember our children time? When we are children, we are interesting in almost everything ...

随机推荐

  1. hdu1978How many ways (记忆化搜索+DFS)

    Problem Description 这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m).游戏的规则描述如下: 1.机器人一开始在棋盘的起始点并有起始点所标 ...

  2. [RxJS] Reactive Programming - Using cached network data with RxJS -- withLatestFrom()

    So now we want to replace one user when we click the 'x' button. To do that, we want: 1. Get the cac ...

  3. JavaScript深拷贝和浅拷贝

    1. 基本类型 和 对象类型 他们最大的区别就是在于他们的传值方式. 基本类型是传值 对象类型就是传引用. 这里复制一份obj叫做obj2, 这里修改了obj2的b为100 同时也修改了obj1.b. ...

  4. python-文件操作(1)

    本文内容涉及python打开/创建文件对象,文件的读写.文件指针位置的移动.获取命令行参数. 1. open() open函数以指定模式返回一个file对象,如: file_object = open ...

  5. DevExpress控件-GridControl根据条件改变单元格/行颜色--转载

    DevExpress控件-数据控件GridControl,有时我们需要根据特定条件改变符合条件的行或者单元格颜色达到突出显示目的,现在动起鼠标跟我一起操作吧,对的,要达到这个目的您甚至都不用动键盘. ...

  6. 英文长单词断行 word-break VS word-wrap

    你真的了解word-wrap和word-break的区别吗? 这两个东西是什么,我相信至今还有很多人搞不清,只会死记硬背的写一个word-wrap:break-word;word-break:brea ...

  7. asp.net实现将网页内容输出到word并下载到本地

    个人觉得要实现这个功能如果没有类库提供的几个关键函数,还是比较繁琐的.所以首先介绍几个将要在代码中使用的关键函数和参数,然后再说函数实现.注意问题等. 关键函数: 1.函数原型:Response.Ap ...

  8. (转)jQuery插件开发模式

    要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发插件,从而建立起了一个生态系统.这好比大公司们争相做平台一样,得平台者得天下.苹果,微软,谷歌等巨头,都有各自的平台及生态圈 ...

  9. 《第一行代码》学习笔记29-内容提供器Content Provider(2)

    1.查询操作: if (cursor != null) { while (cusor.moveToNext()) { String column1 = cursor.getString(cursor. ...

  10. hive函数总结-字符串函数

    hive 查看函数: show  functions; parse_url: parse_url(url, partToExtract[, key]) - extracts a part from a ...