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 (Java/Others)
Total Submission(s): 4075    Accepted Submission(s): 1063

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

卡了一下check,在宽>长那里 。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <vector>
#include <queue>

using namespace std ;
typedef long long LL ;
typedef pair<int,int> pii;
#define X first
#define Y second
const int N = 1010;
struct Blocks {
    LL a , b , c , d , area ;
    bool operator < ( const Blocks &A ) const {
        if( a != A.a ) return a < A.a ;
        else if( b != A.b ) return b < A.b ;
        else return d > A.d ;
    }
}e[N];
LL dp[N] ;
int main ()  {
    #ifdef LOCAL
        freopen("in.txt","r",stdin);
    #endif // LOCAL
    int _ , cas =1 , n ;
    while( cin >> n && n ) {
        memset( dp , 0 , sizeof dp );
        for( int i = 0 ; i < n ; ++i ) {
            cin >> e[i].a >> e[i].b >> e[i].c >> e[i].d ;
            if(e[i].a > e[i].b ) swap(e[i].a, e[i].b );
            e[i].area =  e[i].a * e[i].b ;
        }
        sort( e  , e + n  ) ;
        for( int i = 0 ; i < n ; ++i ) {
            dp[i] = e[i].c ;
            for( int j = 0 ; j < i ; ++j ) {
                if( e[i].d == 0 && e[j].a <= e[i].a && e[j].b <= e[i].b )
                    dp[i] = max( dp[i] , dp[j] + e[i].c );
                if( e[i].d == 1 && e[j].a <= e[i].a && e[j].b <= e[i].b && e[j].area < e[i].area )
                    dp[i] = max( dp[i] , dp[j] + e[i].c );
                if( e[i].d == 2 && e[j].a < e[i].a && e[j].b < e[i].b )
                    dp[i] = max( dp[i] , dp[j] + e[i].c );
            }
        }
        LL ans = 0 ; for( int i = 0 ; i < n ; ++i ) ans = max( ans , dp[i] );
        cout << ans << endl ;
    }
}

时间: 2024-10-05 03:12:15

hdu 4001 To Miss Our Children Time( sort + DP )的相关文章

HDU 4001 To Miss Our Children Time (动态规划)

To Miss Our Children Time 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

HDU 4001 To Miss Our Children Time dp

戳这里:HDU 4001 //题意:有三种积木,第0种 只能放在长和宽都严格小于它的积木上,第1种 只能放在长和宽都小于等于它 且 面积小于它的积木上,第2种 只能放在长和宽都小于等于它的积木上,dp 求积木的最高高度. 1 #include "bits/stdc++.h" 2 using namespace std; 3 int n; 4 struct Block 5 { 6 int a, b, c, d; 7 }block[1010]; 8 bool cmp(Block A, Bl

HDU 1160 FatMouse&#39;s Speed (sort + dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体按照体重从小到大排序,然后根据速度就是最长下降子序列. 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <algorithm> 3 #include <iostream> 4

hdu 4719 Oh My Holy FFF(线段数+dp)

题目链接:hdu 4719 Oh My Holy FFF 题目大意:队伍里有n个人,给出每个人的身高,他们按照顺序排列,现在要将这n个人分成若干组,每一组的人数不得大于l,并且第i组的最后一个人的身高一定要大于第i?1组的最后一个人的身高.要求最后的权值最大,权值计算方法在题目中,k为组号. 解题思路:dp[i]表示以第i个人作为结尾的最大权值,那么dp[i]肯定是从前面的l-1个中转移过来的,即dp[i]=dp[j]+h[i]2?h[j] 要求h[i]>h[j]. 但是这样的复杂度为o(n2)

HDU 4971 A simple brute force problem.(dp)

HDU 4971 A simple brute force problem. 题目链接 官方题解写的正解是最大闭合权,但是比赛的时候用状态压缩的dp也过掉了- -,还跑得挺快 思路:先利用dfs预处理出每个项目要完成的技术集合,那么dp[i][j]表示第i个项目,已经完成了j集合的技术,由于j这维很大,所以利用map去开数组 代码: #include <cstdio> #include <cstring> #include <algorithm> #include &l

hdu 2993 MAX Average Problem (斜率优化dp入门)

MAX Average Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5855    Accepted Submission(s): 1456 Problem Description Consider a simple sequence which only contains positive integers as

HDU 4865 Peter&#39;s Hobby(概率、dp、log)

给出2个影响矩阵,一个是当天天气对湿度的影响,一个是前一天天气对当天天气的影响. 即在晴天(阴天.雨天)发生Dry(Dryish.Damp.Soggy)的概率,以及前一天晴天(阴天.雨天)而今天发生晴天(阴天.雨天)的概率. 其中第一天的晴天阴天雨天概率为0.63,0.17,0.20 输入n天的湿度情况,输出最有可能的n天的天气. 用dp[i][j]表示第i天为j天气的概率,用pre[i][j]表示它的前驱. 注意由于概率相乘次数过多,要用log放大..不然会接近0.精度不够.误差大 dp[i]

HDU - 4971 A simple brute force problem. (DP)

Problem Description There's a company with several projects to be done. Finish a project will get you profits. However, there are some technical problems for some specific projects. To solve the problem, the manager will train his employee which may

hdu 1224 Free DIY Tour(最长路/dp)

http://acm.hdu.edu.cn/showproblem.php?pid=1224 基础的求最长路以及记录路径.感觉dijstra不及spfa好用,wa了两次. #include <stdio.h> #include <algorithm> #include <set> #include <map> #include <vector> #include <math.h> #include <string.h> #