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**\n",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\n",++Case,ans);
}
return 0;
}
ZOJ1093 动态规划的更多相关文章
- 增强学习(三)----- MDP的动态规划解法
上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...
- 简单动态规划-LeetCode198
题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...
- 动态规划 Dynamic Programming
March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...
- 动态规划之最长公共子序列(LCS)
转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...
- C#动态规划查找两个字符串最大子串
//动态规划查找两个字符串最大子串 public static string lcs(string word1, string word2) { ...
- C#递归、动态规划计算斐波那契数列
//递归 public static long recurFib(int num) { if (num < 2) ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- 【BZOJ1700】[Usaco2007 Jan]Problem Solving 解题 动态规划
[BZOJ1700][Usaco2007 Jan]Problem Solving 解题 Description 过去的日子里,农夫John的牛没有任何题目. 可是现在他们有题目,有很多的题目. 精确地 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
随机推荐
- 用yum查询想安装的软件
1.使用YUM查找软件包 命令:yum search~ 2.列出所有可安装的软件包 命令:yum list 3.列出所有可更新的软件包 命令:yum list updates 4.列出所有 ...
- 查找MobileSafari WebKit revision number的方法
Mobile Safari是开源的Mac Safari的iOS版本,然而iOS WebKit并不完全开源,只公开了部分的WebCore和JavaScriptCore.有时需要知道iOS Safari的 ...
- HADOOP之MAPREDUCE程序应用二
摘要:MapReduce程序进行单词计数. 关键词:MapReduce程序 单词计数 数据源:人工构造英文文档file1.txt,file2.txt. file1.txt 内容 Hello Ha ...
- HOJ 2245 浮游三角胞(数学啊 )
题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2245 Time Limi ...
- 可运行jar包调用exe可运行文件,子进程阻塞
背景: 须要在项目的測试工具中加入一个button,点击后直接打开某exe工具. 这个工具的功能是导入txt文件,转为excel报表输出. 无奈解析了两行之后就停止不动了,也不报错.关闭測试工具后,就 ...
- [JS练习] 瀑布流照片墙
记录JS实现瀑布流照片墙效果 首先是前端页面 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- SQL视图索引
视图: 视图就相当于一个查询结果,它相对应的是表 表----真正存储数据的地方 视图---不存储数据,展示查询的结果 注意: 1.视图就是为了查询数据方便.一般不要试图向视图中插入数据,容易出错. 2 ...
- jQuery EasyUI API 中文文档 - 布局(Layout)
<html> <head> <script src="jquery-easyui/jquery.min.js"></script> ...
- 4、深入理解Bean
本节知识点: 1. Bean 的自己主动装配(了解) 2. bean 之间的关系:继承:依赖 3.Bean 的作用域:能够在 <bean> 元素的 scope 属性里设置 Bean 的作用 ...
- 服务器编程入门(7)I/O复用
问题聚焦: 前篇提到了I/O处理单元的四种I/O模型. 本篇详细介绍实现这些I/O模型所用到的相关技术. 核心思想:I/O复用 使用情景: 客户端程序要同时处理多个socket ...