https://vjudge.net/problem/UVA-10618

这道题目题意很复杂,代码也是参考了别人的,因为自己实在是写不出。d[i][a][b][s]表示分析到第i个箭头时,此时左脚处于a,右脚处于b,上次移动的脚为s时的最小能量消耗。

 #include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std; #define INF 10000000 char str[];
int len;
int d[][][][];
int action[][][][];
int pos[];
char place[] = ".LR"; int energy(int a, int ta)
{
if (a == ta) return ; //该脚没有移动
if (a + ta == ) return ; //该脚移动到相对箭头
return ; //该脚移动到相邻箭头
} int energy(int a, int b, int s, int f, int t, int& ta, int& tb)
{
ta = a;
tb = b;
//移动之后的脚的位置
if (f == ) //左脚
ta = t;
if (f == ) //右脚
tb = t; if (ta == tb) return -; //移动之后两只脚在同一位置
if (ta == && tb == ) return -; //背向跳舞机状态
if (a == && tb != b) return -; //左脚在右箭头时,不能移动右脚
if (b == && ta != a) return -; //右脚在左箭头时,不能移动左脚 int e = ;
if (f == ) //没有移动
e = ;
else if (f != s) //和上个周期移动的脚不同
e = ;
else
{
if (f == )
e = energy(a, ta);
else
e = energy(b, tb);
}
return e;
} void update(int i, int a, int b, int s, int f, int t)
{
int ta, tb;
int e = energy(a, b, s, f, t, ta, tb);
if (e < ) return;
//逆推
int cost = d[i + ][ta][tb][f] + e;
int& ans = d[i][a][b][s];
if (ans>cost)
{
ans = cost;
action[i][a][b][s] = f * + t;
}
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
pos['U'] = ;
pos['D'] = ;
pos['L'] = ;
pos['R'] = ;
while (cin >> str)
{
if (str[] == '#') break;
len = strlen(str);
memset(d, , sizeof(d)); //逆推导
for (int i = len - ; i >= ; i--)
{
for (int a = ; a < ; a++)
for (int b = ; b < ; b++)
{
//两只脚不可能在同一箭头上
if (a == b) continue;
for (int s = ; s < ; s++)
{
d[i][a][b][s] = INF;
if (str[i] == '.')
{
//不移动
update(i, a, b, s, , );
//任意往4个位置移动
for (int t = ; t < ; t++)
{
update(i, a, b, s, , t);
update(i, a, b, s, , t);
}
}
else
{
update(i, a, b, s, , pos[str[i]]); //左脚移动到指定位置
update(i, a, b, s, , pos[str[i]]); //右脚移动到指定位置
}
}
}
}
//初始时左脚在左箭头,右脚在右箭头
int a = , b = , s = ;
for (int i = ; i < len; i++)
{
int f = action[i][a][b][s] / ;
int t = action[i][a][b][s] % ;
cout << place[f];
s = f;
if (f == )
a = t;
else if (f == )
b = t;
}
cout << endl;
}
}

UVa 10618 跳舞机的更多相关文章

  1. 【暑假】[深入动态规划]UVa 10618 Fun Game

    UVa 10618 Fun Game 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36035 思路:   一圈人围坐 ...

  2. 【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall

    UVa 10618 Fixing the Great Wall 题目:  http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=361 ...

  3. 【暑假】[深入动态规划]UVa 10618 Tango Tango Insurrection

    UVa 10618 Tango Tango Insurrection 题目: Problem A: Tango Tango Insurrection You are attempting to lea ...

  4. UVA 10618 Tango Tango Insurrection

    https://vjudge.net/problem/UVA-10618 题目 你想学着玩跳舞机.跳舞机的踏板上有4个箭头:上.下.左.右.当舞曲开始时,屏幕上会有一些箭头往上移动.当向上移动箭头与顶 ...

  5. uva 10618 Tango Tango Insurrection 解题报告

    Tango Tango Insurrection Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebu ...

  6. 【Uva 10618】Tango Tango Insurrection

    [Link]: [Description] 玩跳舞机. 有一定的约束. 归纳起来就是以下三点 1.两只脚不能同时踩一个位置 2.如果左脚踩在了右键上,那么下一次移动的一定要是左脚 3.如果右脚踩在了左 ...

  7. 【暑假】[深入动态规划]UVa 10618 The Bookcase

    UVa 12099  The Bookcase 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42067 思路:    ...

  8. uva 1291(dp)

    题意:有一台跳舞机,中间是0.上左下右分别代表1 2 3 4,初始状态人站在中间.两仅仅脚都踏在0上,然后给出一段序列以0为结束,要按顺序踩出来,从0踏到四个方向须要消耗2点能量,从一个方向到相邻的方 ...

  9. UVA 1291 Dance Dance Revolution(DP)

    意甲冠军:跳舞机有一个上5积分,分别central, top, bottom, left, right分,区区足站立还是需要1点物理,从一个单纯的脚central点上须要2点体力,从一个点上移动到相邻 ...

随机推荐

  1. string、const char*、 char* 、char[]相互转换(待整理)

    string.const char*. char* .char[]相互转换(全) https://blog.csdn.net/rongrongyaofeiqi/article/details/5244 ...

  2. C#集合中的Add与AddRange方法

    C#.NET的集合主要位于System.Collections和System.Collections.Generic(泛型)这两个namespace中. 1.System.Collections 比如 ...

  3. iOS学习之VFL语言简介

    什么是VFL语言 VFL(Visual Format Language),“可视化格式语言”. VFL是苹果公司为了简化autolayout的编码而推出的抽象语言. 语法说明 H:[cancelBut ...

  4. HTML 显示/隐藏DIV的技巧(visibility与display的差别)

    参考链接:http://blog.csdn.net/szwangdf/article/details/1548807 div的visibility可以控制div的显示和隐藏,但是隐藏后页面显示空白: ...

  5. HDU 5059 Help him(简单模拟题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目大意: 给定一个字符串,如果这个字符串是一个整数,并且这个整数在[a,b]的范围之内(包括a,b),那 ...

  6. lnmp之php5.6.29安装

    linux下lnmp环境之php安装 为了防止出现缺失,安装下面集成,复制的时候请将这个复制成一个整行,下面3行是一整行 [root@localhost src]# yum -y install gc ...

  7. 线段树(I tree)

    Codeforces Round #254 (Div. 2)E题这题说的是给了一个一段连续的区间每个区间有一种颜色然后一个彩笔从L画到R每个区间的颜色都发生了 改变然后 在L和R这部分区间里所用的颜色 ...

  8. Repeater 控件使用总结

      关于Repeater控件使用的一些总结,希望能对将来有机会看到这篇日志的同事有所帮助.也是为了在自己开发有所遗忘的时候能够参考一下.前言:Repeater是一个迭代控件,什么是迭代控件呢?书本上的 ...

  9. Linux基础命令---diffstat

    diffstat 这个程序读取diff的输出,并显示每个文件的插入.删除和修改的直方图.Diffstat是一个用于检查大型复杂修补程序文件的程序.它从包含diff输出的一个或多个输入文件中读取,生成针 ...

  10. http协议/获得请求/中文参数处理/访问数据库

    # 1. http协议(了解)## (1)什么是http协议?一种网络应用层协议,规定了浏览器与web服务器之间如何通信以及相应的的数据包的结构.注:tcp/ip协议:保证数据可靠的传递.(UDP不可 ...