UVa 437 The Tower of Babylon】的更多相关文章

传送门 Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story: The babylonians had n…
Description   Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story: The babylonians had n t…
 题意  给你n种长方体  每种都有无穷个  当一个长方体的长和宽都小于还有一个时  这个长方体能够放在还有一个上面  要求输出这样累积起来的最大高度 由于每一个长方体都有3种放法  比較不好控制   能够把一个长宽高分成三个长方体  高度是固定的  这样就比較好控制了 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define maxn 105 int x[…
每一个长方形都有六种放置形态,其实可以是三种,但是判断有点麻烦直接用六种了,然后按照底面积给这些形态排序,排序后就完全变成了LIS的问题.代码如下: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 1818 struct Node { int x,y,z,area; void init(int a,…
题目大意是根据所给的有无限多个的n种立方体,求其所堆砌成的塔最大高度. 方法1,建图求解,可以把问题转化成求DAG上的最长路问题 #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #include <vector> using namespace std; ; struct Node{ int x; int y; int z; Node(in…
题意:有n(n≤30)种立方体,每种有无穷多个.要求选一些立方体摞成一根尽量高的柱子(可以自行选择哪一条边作为高),使得每个立方体的底面长宽分别严格小于它下方立方体的底面长宽. 评测地址:http://acm.hust.edu.cn/vjudge/problem/19214 AC代码: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 50010 i…
题目传送门 题意:给出一些砖头的长宽高,砖头能叠在另一块上要求它的长宽都小于下面的转头的长宽,问叠起来最高能有多高 分析:设一个砖头的长宽高为x, y, z,那么想当于多了x, z, y 和y, x, z的砖头,如果i能叠在j上,那么g[i][j] = true,转换成DAG问题,dp[i]表示第i块叠在最上部最高的高度 收获:转换成经典模型 代码: /************************************************ * Author :Running_Time…
传送门 题意 有 n 种立方体,每种都有无穷多个. 要求选一些立方体摞成一根尽量高的柱子(在摞的时候可以自行选择哪一条边作为高): 立方体 a 可以放在立方体 b 上方的前提条件是立方体 a 的底面长宽分别严格小于立方体 b 的底面长宽: 求最大高度: 思路 对于立方体 a(x,y,z)((长,宽,高)),因为每个立方体都有无穷个,所以 a 要拆成三个: a1(x,y,z) , a2(x,z,y) , a3(y,z,x) 即分别以 z,y,x 作为高: 对于任意两个立方体 a,b ,如果 b 可…
据说是DAG的dp,可用spfa来做,松弛操作改成变长.注意状态的表示. 影响决策的只有顶部的尺寸,因为尺寸可能很大,所以用立方体的编号和高的编号来表示,然后向尺寸更小的转移就行了. #include<bits/stdc++.h> using namespace std; #define MP make_pair #define fi first #define se second typedef pair<int,int> pii; ; ]; ]; ]; ][]; int mai…
The Tower of Babylon Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 437 Appoint description:  System Crawler  (2015-08-29) Description   Perhaps you have heard of the legend of the Tower of Babylon.…
转自:https://mp.weixin.qq.com/s/oZVj8lxJH6ZqL4sGCXuxMw The Tower of Babylon(巴比伦塔) Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this…
The Tower of Babylon Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story: The babylonians…
The Tower of Babylon Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2207   Accepted: 1244 Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line…
Problem UVA437-The Tower of Babylon Accept: 3648  Submit: 12532Time Limit: 3000 mSec Problem Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the ed…
题目:The Tower of Babylon 这是一个DAG 模型,有两种常规解法 1.记忆化搜索, 写函数,去查找上一个符合的值,不断递归 2.递推法 方法一:记忆化搜索 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; struct node { int x…
The Tower of Babylon My Tags Cancel - Seperate tags with commas. Source : University of Ulm Internal Contest 1996 Time limit : 5 sec Memory limit : 32 M Submitted : 303, Accepted : 155 Perhaps you have heard of the legend of the Tower of Babylon. Now…
 The Tower of Babylon  Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story: The babylonian…
The Tower of Babylon 题意:给你n种石头,长x,宽y,高z,每种石头数目无限,一块石头能放到另一块上的条件是:长和宽严格小于下面的石头.问叠起来的最大高度. /* 有些类似“叠箱子”问题,看起来一种砖有无限多个,其实最多只能用到两次. 说下我的思路吧,一块砖有3个数据,虽然3!=6,但本质上还是只有3种,把这三种都表示出来,使x<=y:这样就有了3n组数据.因为我不会建图,就把这3n组数据再排列一下,使一块砖只能放到它后面的砖之上,而绝不能放到之前的砖上,即按x为一级y为二级…
The Tower of Babylon Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 224164-bit integer IO format: %lld      Java class name: Main Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many d…
https://odzkskevi.qnssl.com/5e1fdf8cae5d11a8f572bae96d6095c0?v=1507521965 Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contes…
UVA437 The Tower of Babylon 题解 初始时给了 \(n\) 种长方体方块,每种有无限个,对于每一个方块,我们可以选择一面作为底.然后用这些方块尽可能高地堆叠成一个塔,要求只有一个方块的底的两条边严格小于另一个方块的底的两条边,这个方块才能堆在另一个上面. 问题的思考在于每种方块有无限个,如果我们直接利用该条件问题会变得比较复杂.其实仔细考虑方块堆叠的要求,会发现这是一个约束很强的条件. 注意到,方块堆叠的要求描述的对象不只是方块本身,更细地说,它应该描述的是方块摆放方式…
[题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=378 [题意] 给你n个方形; 由3个属性,长宽高决定; 你可以任意摆放这个方形(即把哪一面朝下方); 然后每种方形都有无限个; 一个方形能够摆在另外一个方形上面,当且仅当这个方形的长和宽都严格大于另外一个方形的长和宽(即changi>changj &&…
题意: 有n种类型的长方体,每种长方体的个数都有无限个.当一个长方体的长和宽分别严格小于另一个长方体的长和宽的时候,才可以把这个放到第二个上面去.输出这n种长方体能组成的最大长度. 分析: 虽说每种都有无限个,可每种长方体一共的“姿态”最多也只有三种,将它们三个边长分别作为高.然后按照底面排序,就转化为最大上升子列的问题. 代码中采用了“人人为我”的方法. //#define LOCAL #include <iostream> #include <algorithm> #inclu…
题意:有n种立方体,每种都有无穷多个.选一些正方体摞成一根尽量高的柱子(可以选择任意一条边做高),使得每个立方体的底面长宽分别严格小于它下方的立方柱的底面长宽. 题解:可以套用DAG最长路算法,可以使用二元组来表示每个立方体的每一条边,如v[n][2]就可以用来表示第n个立方块的3个边. DAG最长路算法: int dp(int i,int j) { int &ans=dist[i][j]; ) return ans;///表示已经查找过此种状态 ans=;///根据题意赋相应的初值 ],v2[…
题目:题目链接 思路:每个方块可以用任意多次,但因为底面限制,每个方块每个放置方式选一个就够了,以x y为底 z 为高,以x z为底 y 为高,以y z为底 x为高,因为数据量很小,完全可以把每一种当成DAG上的一个结点,然后建图找最长路径. AC代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring>…
[Solution] 接上一篇,在处理有向无环图的最长链问题的时候,可以在做拓扑排序的同时,一边做DP; 设f[i]表示第i个方块作为最上面的最高值; f[y]=max(f[y],f[x]+h[y]);(x−>y)∈E 这样可以保证,按阶段进行DP,每次在获取f[x]的时候,你可以保证f[x]已经获得了; 最后取max(f[1..n]) [Code] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<…
题意: 一堆石头,给定长宽高,每种石头均可以使用无数次,问这堆石头可以叠放的最高高度,要求下面的石头的长和宽分别严格大于上面石头的长和宽. 分析: 采用DAG最长路算法,由于长宽较大,不能直接用于表示状态,因此采用d[i][x]表示以第i块石头为最高点,以其第x个边为高所能达到的最大高度,其中i为石头标号,x代表长/宽/高,然后根据长宽高要求构造DAG,最后记忆化搜索求出最长路. 代码: #include<iostream> #include<cstring> #include&l…
题目链接:https://uva.onlinejudge.org/external/4/437.pdf 题意:巴比伦塔: 给出n种立方体,一个立方体能放到另一个立方体上,必须满足,底面一定要小于下面的立方体.求巴比伦塔最多堆多高? 分析: DAG很容易想到,主要是状态的描叙. 一个立方体,他有3种情况,状态的描叙就用dp[id][3],此时dp[][i] I 来记录哪个是高. #include <bits/stdc++.h> using namespace std; ][]; ][]; int…
巴比伦塔 紫书P269 看完紫书,终于可以自己写一个dp了 :) [题目链接]巴比伦塔 [题目类型]DAG上dp &题意: 有n种立方体 n<=30,每种有无穷个,要求选一些立方体摞成一根尽量高的柱子,上面的立方体长和宽必须严格小于下面的. &题解: 看紫书前,我的想法: 这题就把所有的3种情况排个序啊,根据长和宽排,之后累计加高,就好了. 看紫书后,我的想法: 这是一个二元关系,而且没有环,又范围很小,所以用邻接矩阵建图,也就转化成DAG上的最长路径了. 差距: 之前的想法太幼稚,…
题意: 有n个,长x宽y高z的长方体,把这些长方体摞起来,上面长方体底面的长宽一定要小于下面的,求能摞的最大高度. 分析: 一个长方体,可以有三种放法,先把所有放的状态存起来,按底面升序排列,dp[i]前i个能构成的最大高度,dp[i]=max(dp[i],dp[j]+h)  h为当前长方体高度 #include <map> #include <set> #include <list> #include <cmath> #include <queue&…