uva10051(dp 立方体塔, 拆分)
来源:互联网 发布:kindle订阅知乎周刊 编辑:程序博客网 时间:2024/05/17 01:12
题意:有n个立方体,每一面都有颜色,现在要用他们堆出高度尽量高的塔,条件是,两个接触的块,他们的接触面颜色要一样,同时上面的块重量要严格小于他下面的。
与LIS思想一样,题目给出的数据是按重量递增的
#include<iostream>#include<algorithm>#include<map>#include<cstdio>#include<cstdlib>#include<vector>#include<cmath>#include<cstring>#include<stack>#include<string>#include<set>#include<fstream>using namespace std;#define pb push_back#define cl(a,b) memset(a,b,sizeof(a))#define bug printf("===\n");#define rep(a,b) for(int i=a;i<b;i++)#define rep_(a,b) for(int i=a;i<=b;i++)#define P pair<int,int>#define X first#define Y second#define vi vector<int>const int maxn=50002;const int inf=999999999;typedef long long LL;void Max(int&a,int b){if(a<b)a=b;}void Min(int&a,int b){if(a>b)a=b;}int color[6];char s[6][20]={"front", "back", "left", "right", "top" ,"bottom"};int dp[maxn];int f[maxn];struct node{ int top,bom,weight,s; node(){} node(int a,int b,int c,int r):top(a),bom(b),weight(c),s(r){}}p[maxn];void out(int x){ if(x==-1)return ; out(f[x]); printf("%d %s\n",p[x].weight,s[p[x].s]);}int main(){ int n; int cas=0; while(~scanf("%d",&n)&&n){ int k=0; for(int i=0;i<n;i++){ for(int j=0;j<6;j++){ scanf("%d",&color[j]); } for(int j=0;j<6;j++){ if(j%2){ p[k++]=node(color[j],color[j-1],i+1,j); }else { p[k++]=node(color[j],color[j+1],i+1,j); } } } cl(dp,0); cl(f,-1); int ans=0,index=0; for(int i=0;i<k;i++){ for(int j=i+1;j<k;j++)if(dp[j]<dp[i]+1&&p[j].weight>p[i].weight&&p[j].top==p[i].bom){ dp[j]=dp[i]+1; f[j]=i; } if(ans<dp[i]){ ans=dp[i]; index=i; } } if (cas) printf("\n"); printf("Case #%d\n%d\n", ++cas, ans + 1); out(index); } return 0;}/*31 2 2 2 1 23 3 3 3 3 33 2 1 1 1 1101 5 10 3 6 52 6 7 3 6 95 7 3 2 1 91 3 3 5 8 106 6 2 2 4 41 2 3 4 5 610 9 8 7 6 56 1 2 3 4 71 2 3 3 2 13 2 1 1 2 30*/
0 0
- uva10051(dp 立方体塔, 拆分)
- uva10051
- poj 3181 dp+高精度(数字拆分)
- [动态规划]整数拆分(纯DP)
- poj 3017 dp+单调队列(拆分序列)
- dp(整数拆分 uva10313 - Pay the Price)
- UVA 10721 Bar Codes(DP,整数拆分)
- string 字符串拆分 二维dp(斜率优化)
- ccount 进制拆分(Lucas 数位dp)
- 【DP~最大子立方体】吃西瓜
- 立方体之塔 10051
- flex3d效果(立方体)
- 立方体
- UVA10051 Tower of Cubes
- UVA10051- - Tower of Cubes
- UVa Problem 10051 Tower of Cubes (立方体之塔)
- [SDOI2008] 立方体覆盖 - 矩形切割(立方体切割)
- 移动立方体算法(MC)
- [线段树] poj3468 A Simple Problem with Integers
- QTP/UFT以XPath作为属性标识对象
- app包中的fragment和v4包中的fragment的使用的区别
- html meta标签常用属性整理
- Android Studio系列教程一 下载和安装
- uva10051(dp 立方体塔, 拆分)
- MARK
- 的范德萨范德萨
- windows上安装Mongodb提示主机拒绝
- sourceinsight常用快捷键和设置
- Redis 使用基础
- Http协议详解
- Android开发之详解五大布局
- Alcatraz在Xcode6.4版本不启动的解决