zoukankan      html  css  js  c++  java
  • ZOJ1093 动态规划

    给你n砖,有三个长宽高。每一个无限制的访问。叠加在一个条件的长度和宽度必须严格格长度和宽度大于下面的一个,叠加求最大高度。

    思维:

    每块砖终于放置在根据本方法可以把六种,然后,对于长度和宽度排序。这是LIS的变化的问题


    #include<iostream>
    #include<cstdio>
    #include<list>
    #include<algorithm>
    #include<cstring>
    #include<string>
    #include<queue>
    #include<stack>
    #include<map>
    #include<vector>
    #include<cmath>
    #include<memory.h>
    #include<set>
    #include<cctype>
    
    #define ll long long
    
    #define LL __int64
    
    #define eps 1e-8
    
    #define inf 0xfffffff
    
    //const LL INF = 1LL<<61;
    
    using namespace std;
    
    //vector<pair<int,int> > G;
    //typedef pair<int,int > P;
    //vector<pair<int,int> > ::iterator iter;
    //
    //map<ll,int >mp;
    //map<ll,int >::iterator p;
    
    int box[500][3];
    int dp[1000];
    
    int cnt;
    
    typedef struct Node {
    	int x,y,z;
    };
    
    Node node[500];
    
    void init() {
    	memset(box,0,sizeof(box));
    	memset(dp,0,sizeof(dp));
    	cnt = 0;
    }
    
    /*void cal(int x,int y,int z) {
    box[cnt][0] = x,box[cnt][1] = y,box[cnt++][2] = z;
    box[cnt][0] = y,box[cnt][1] = x,box[cnt++][2] = z;
    box[cnt][0] = y,box[cnt][1] = z,box[cnt++][2] = x;
    box[cnt][0] = z,box[cnt][1] = y,box[cnt++][2] = x;
    box[cnt][0] = x,box[cnt][1] = z,box[cnt++][2] = y;
    box[cnt][0] = z,box[cnt][1] = x,box[cnt++][2] = y;
    }*/
    
    void cal(int x,int y,int z) {
    	node[cnt].x = x,node[cnt].y = y,node[cnt++].z = z;
    	node[cnt].x = y,node[cnt].y = x,node[cnt++].z = z;
    	node[cnt].x = y,node[cnt].y = z,node[cnt++].z = x;
    	node[cnt].x = z,node[cnt].y = y,node[cnt++].z = x;
    	node[cnt].x = x,node[cnt].y = z,node[cnt++].z = y;
    	node[cnt].x = z,node[cnt].y = x,node[cnt++].z = y;
    }
    
    bool cmp(Node x,Node y) {
    	if(x.x == y.x) {
    		if(x.y == y.y)return x.z < y.z;
    		return x.y < y.y;
    	} 
    	return x.x < y.x;
    }
    
    int main() {
    	int n;
    	int	Case = 0;
    	while(scanf("%d",&n),n) {
    		init();
    		for(int i=0;i<n;i++) {
    			int x,y,z;
    			scanf("%d %d %d",&x,&y,&z);
    			cal(x,y,z);
    		}
    		int ans = 0;
    		sort(node,node+cnt,cmp);
    		/*for(int i=0;i<cnt;i++) {
    			printf("%d %d %d**
    ",node[i].x,node[i].y,node[i].z);
    		}*/
    		for(int i=0;i<cnt;i++)
    			dp[i] = node[i].z;
    		for(int i=0;i<cnt;i++) {
    			for(int j=1;j<i;j++) {
    				int a = node[j].x;
    				int b= node[i].x;
    				int c = node[j].y;
    				int d= node[i].y;
    				if(node[j].x < node[i].x && node[j].y < node[i].y) {
    					dp[i] = max(dp[j] + node[i].z,dp[i]);
    				}
    			}
    			if(ans < dp[i])
    				ans = dp[i];
    		}
    		printf("Case %d: maximum height = %d
    ",++Case,ans);
    	}
    	return 0;
    }


  • 相关阅读:
    数字图像处理(一)之灰度转换和卷积python实现
    ArcEngine+C# 森林资源仿真系统 核心代码
    Dijkstra和Floyd算法遍历图的核心
    python像操作文件一样操作内存的模块 StringIO
    python操作Redis方法速记
    python中时间处理标准库DateTime加强版库:pendulum
    utittest和pytest中mock的使用详细介绍
    《金字塔原理》 读书笔记
    python轻量级orm框架 peewee常用功能速查
    docker中安装的mysql无法远程连接问题解决
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5038640.html
Copyright © 2011-2022 走看看