将每一个分解为六个两面的 简单地dp 回溯输出路径.....

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
struct cc
{
int top,bom,fa,w;
void f(int a, int b, int c, int d)
{
top = a;
bom = b;
fa = c;
w = d;
}
};
cc cube[3100];
char face[7][10] = { "front","back", "left", "right", "top", "bottom"};
int dp[3100],cu[7],p[3100];
void printpath(int k)
{
if(k == -1)
return ;
printpath(p[k]);
printf("%d %s\n",cube[k].w, face[cube[k].fa]);
}
int main()
{
int n, ca = 1;
while(scanf("%d", &n) == 1 && n)
{
int m = 0;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < 6; j++)
scanf("%d",&cu[j]);
for(int j = 0; j < 6; j++)
{
cube[m++].f(cu[j], j%2 == 1?cu[j-1]:cu[j+1], j, i+1);
}
}
memset(dp, 0, sizeof( dp));
memset(p, -1, sizeof( p));
int _max = 0, k;
for(int i = 0; i < m; i++)
for(int j = i+1; j < m; j++)
if(cube[j].w > cube[i].w && cube[i].bom == cube[j].top && dp[j] < dp[i]+1)
{
dp[j] = dp[i]+1;
p[j] = i;
if(dp[j] > _max)
{
_max = dp[j];
k = j;
}
}
printf("Case #%d\n%d\n",ca++,_max+1);
printpath(k);
puts("");
}
return 0;
}

uva 10051的更多相关文章

  1. uva 10051 Tower of Cubes(DAG最长路)

    题目连接:10051 - Tower of Cubes 题目大意:有n个正方体,从序号1~n, 对应的每个立方体的6个面分别有它的颜色(用数字给出),现在想要将立方体堆成塔,并且上面的立方体的序号要小 ...

  2. Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 5. Dynamic Programming

    10192 最长公共子序列 http://uva.onlinejudge.org/index.php?option=com_onlinejudge& Itemid=8&page=sho ...

  3. UVa Problem 10051

    这题有点类似LIS,由于颜色最多100种,所以只需建立一个100的数组,按对立面的关系以某种颜色为向上面的最大值就可以了.   #include <iostream> #include & ...

  4. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  5. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  6. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  7. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  8. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  9. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

随机推荐

  1. Android 如何监听返回键,弹出一个退出对话框

    android 如何监听返回键点击事件,并创建一个退出对话框, 防止自己写的应用程序不小心点击退出键而直接退出.自己记录下这个简单的demo,备用. public class BackKeyTest ...

  2. Agile.Net 组件式开发平台 - 数据报表组件

    Agile.Report.dll 文件为平台数据报表支持库,基于FasstReport.Net扩展重写,提供了非常强大的自定义报表的功能使开发者为应用程序快速有效地生成报表.报表类库提供了创建报表所需 ...

  3. 使用Win7+IIS7发布网站或服务步骤

    1.安装IIS服务:控制面板=>程序=>打开或关闭WINDOWS 功能=>Internet 信息服务=>WEB服务管理器全选√ 和万维网服务:应用程序开发功能: 2.打开IIS ...

  4. Bootstrap 标签的变体 实例样式

    Bootstrap 标签样式,代码如下: <!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 标签的 ...

  5. 【转】 SqlServer性能检测和优化工具使用详细

    http://blog.csdn.net/dcx903170332/article/details/45917387

  6. 【leetcode】365. Water and Jug Problem

    题目描述: You are given two jugs with capacities x and y litres. There is an infinite amount of water su ...

  7. the first blog: record my coding

    try the code "hello world" #include<iostream> using namespace std; int main() { cout ...

  8. Poj 2996 Help Me with the Game

    1.Link: http://poj.org/problem?id=2996 2.Content: Help Me with the Game Time Limit: 1000MS   Memory ...

  9. Poj 2583 Series Determination

    1.Link: http://poj.org/problem?id=2583 2.Content: Series Determination Time Limit: 1000MS   Memory L ...

  10. Ueditor中增加迅雷下载支持

    在项目中有遇到需要在Ueditor中加一个链接,迅雷的开头是thunder 会被默认加上http://   最后的 结果就变成了http://thunder://xxxxx 导致用户点击失败: 其实在 ...