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

题目

你想学着玩跳舞机。跳舞机的踏板上有4个箭头:上、下、左、右。当舞曲开始时,屏幕上会有一些箭头往上移动。当向上移动箭头与顶部的箭头模板重合时,你需要用脚踩一下踏板上的相同箭头。不需要踩箭头时,踩箭头并不会受到惩罚,但当需要踩箭头时,必须踩一下,哪怕已经有一只脚放在了该箭头上。很多舞曲的速度快,需要来回倒腾步子,所以最好写一个程序来帮助你选择一个轻松的踩踏方式,使得能量小号最少。

为了简单起见,将一个八分音符作为一个基本时间单位,每个时间单位要么需要踩一个箭头(不会同时需要踩两个箭头),要么什么都不需要踩。在任意时刻,你的左右脚应放在不同的两个箭头上,且每个时间单位内只有一只脚能动(移动和/或踩箭头),不能跳跃。另外,你必须面朝前方以看到屏幕(即:你不能把左脚放在右箭头上,并且右脚放在左箭头上)。当你执行一个动作(移动和/或踩)时,消耗的能量这样计算

(紫书上的说明是错的= =)

Performing an action with a foot costs 1 unit of energy if it did NOT perform an action in the previous time unit. If it did, then it costs 3 units if it doesn't change arrows, 5 units if it moves to an adjacent arrow, and 7 units if it moves directly across the pad (between Up and Down, or Left and Right).

正常情况下,你的左脚不能放到右箭头上(或者反之),但有一种情况例外:如果你的左脚在上箭头或者下箭头,你可以临时扭着身子用右脚踩左箭头,但是在你的右脚移出左箭头之前,你的左脚都不能移到另一个箭头上。类似地,右脚在上箭头或者下箭头时,你也可以临时用左脚踩右箭头。一开始,你的左脚在左箭头上,右脚在右箭头上。

输入包含最多100组数据,每组数据包含一个长度不超过70的字符串,即各个时间单位需要踩的箭头。L和R分别表示左右箭头,“.”表示不需要踩箭头。输出应是一个长度和输入相同的字符串,表示每个时间单位执行动作的脚。L和R分别是左右脚,“.”表示不踩。比如, .RDLU 的最优解是 RLRLR ,第一次是把右脚放在下箭头上。

题解

因为最多只有70个阶段,所以不会爆栈,直接递归,懒得改迭代了= =

设$dp[l][r][t][id]$为时间为$t$,左脚在$l$,右脚在$r$,且上一次移动了(id==1?左:右)脚

很容易写出转移= =

状态和转移最多$\mathcal{O}(lrt\times id) \leqslant 2240$,完全不管时间限制……

紫书上给的能量消耗说明是错的,害得我改了好久= =

AC代码

#include<bits/stdc++.h>
using namespace std; #define REP(r,x,y) for(register int r=(x); r<(y); r++)
#define PER(r,x,y) for(register int r=(x); r>(y); r--)
#define REPE(r,x,y) for(register int r=(x); r<=(y); r++)
#define PERE(r,x,y) for(register int r=(x); r>=(y); r--)
#ifdef sahdsg
#define DBG(...) printf(__VA_ARGS__)
#else
#define DBG(...) (void)0
#endif
#define iabs(a) ((a)<0?(-(a)):(a))
char ops[80];
int d[4][4][80][3];
inline int getnum(int x) {
switch(ops[x]) {
case 'U': return 0;
case 'L': return 1;
case 'D': return 2;
case 'R': return 3;
case '.': return -1;
}
return -1;
} inline bool can(int l, int r, int ll, int lr) {
if(l==r) return false;
if((ll==2 || ll==0) && lr==1 && l!=ll) return false;
if((lr==2 || lr==0) && ll==3 && r!=lr) return false;
if(l==3 && r==1) return false;
return true;
} inline int cost(int f, int t) {
if(f==t) return 3;
if(iabs(f-t)==2) return 7;
return 5;
} int solve(int l, int r, int t, int id) {
if(ops[t]<=' ') return 0;
int &now = d[l][r][t][id];
if(now>=0) return now;
int num=getnum(t); now=0x3f3f3f3f;
if(num>=0) {
if(can(l,num,l,r)) now=min(now,solve(l,num,t+1, 2)+(id==2?cost(r,num):1));
if(can(num,r,l,r)) now=min(now,solve(num,r,t+1, 1)+(id==1?cost(l,num):1));
} else {
REP(i,0,4) {
if(can(l,i,l,r)) now=min(now,solve(l,i,t+1, 2)+(id==2?cost(r,i):1));
if(can(i,r,l,r)) now=min(now,solve(i,r,t+1, 1)+(id==1?cost(l,i):1));
}
now=min(now,solve(l,r,t+1,0));
}
return now;
}
char ans[80];
int ansn=0;
inline void anx(char x) {
ans[ansn++]=x;
}
bool prn(int l, int r, int t, int id) {
if(ops[t]<=' ') return true;
int &now = d[l][r][t][id];
int num=getnum(t);
if(num>=0) {
if(can(l,num,l,r)) if(now==solve(l,num,t+1, 2)+(id==2?cost(r,num):1))
if(prn(l,num,t+1, 2)) {anx('R'); return 1;}
if(can(num,r,l,r)) if(now==solve(num,r,t+1, 1)+(id==1?cost(l,num):1))
if(prn(num,r,t+1, 1)) {anx('L'); return 1;}
} else {
REP(i,0,4) {
if(can(l,i,l,r)) if(now==solve(l,i,t+1, 2)+(id==2?cost(r,i):1))
if(prn(l,i,t+1,2)) {anx('R'); return 1;}
if(can(i,r,l,r)) if(now==solve(i,r,t+1, 1)+(id==1?cost(l,i):1))
if(prn(i,r,t+1,1)) {anx('L'); return 1;}
}
if(now==solve(l,r,t+1,0)) if(prn(l,r,t+1,0)) {anx('.'); return 1;}
}
return now;
} int main() {
#ifdef sahdsg
freopen("in.txt","r",stdin);
#endif
while(1) {
fgets(ops, 80, stdin); if(ops[0]=='#') break;
memset(d,-1,sizeof d); ansn=0;
solve(1,3,0,0); //DBG("%d\n", d[1][3][0][0]);
prn(1,3,0,0);
while(0<ansn--) putchar(ans[ansn]); putchar('\n');
}
return 0;
}

UVA 10618 Tango Tango Insurrection的更多相关文章

  1. 【Uva 10618】Tango Tango Insurrection

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

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

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

  3. uva 10618 Tango Tango Insurrection 解题报告

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

  4. 【杂题总汇】UVa-10618 Tango Tango Insurrection

    [UVa-10618] Tango Tango Insurrection ◇ 题目 +vjudge 链接+ (以下选自<算法竞赛入门经典>-刘汝佳,有删改) <题目描述> 你想 ...

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

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

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

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

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

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

  8. UVa 10618 跳舞机

    https://vjudge.net/problem/UVA-10618 这道题目题意很复杂,代码也是参考了别人的,因为自己实在是写不出.d[i][a][b][s]表示分析到第i个箭头时,此时左脚处于 ...

  9. Getting Started with Google Tango(Google Tango开始教程)

    https://developers.google.com/tango/ Build apps that understand space and motion in high fidelity on ...

随机推荐

  1. Web前端 页面功能——点击按钮返回顶部的实现方法

    1. 最简单的静态返回顶部,点击直接跳转页面顶部,常见于固定放置在页面底部返回顶部功能 方法一:用命名锚点击返回到顶部预设的id为top的元素 html代码 <a href="#top ...

  2. 《React设计模式与最佳实践》笔记

    书里的demo都是15.3.2以下版本的,有些demo用最新的react 16.x版本会报错,安装包的时候记得改一下版本   第一章 React 基础 命令式编程描述代码如何工作,而声明式编程则表明想 ...

  3. Android远程桌面助手(Build 0662)

    ARDC Build 0662, Jul 19, 2017 OPT: 1440*2560及以下分辨率设备,帧速能稳定在20帧~25帧 FIX: 拖拽文件的路径中包含空格的处理 ADD: 支持Ctrl+ ...

  4. Android BottomNavigationBar导航栏

    基本属性 setActiveColor //选中item的字体颜色 setInActiveColor //未选中Item中的颜色 setBarBackgroundColor//背景颜色 setMode ...

  5. spring学习总结——装配Bean学习二(JavaConfig装配bean)

    通过Java代码装配bean 前言:上面梳理了通过注解来隐式的完成了组件的扫描和自动装配,下面来学习下如何通过显式的配置的装配bean: 使用场景:比如说,你想要将第三方库中的组件装配到你的应用中,在 ...

  6. TreeView 节点拖拽

    public Form1() { InitializeComponent(); treeView1.AllowDrop = true; treeView1.ItemDrag += new ItemDr ...

  7. python3 判断数据类型

    def estType(): eventList = [1, 'Tom', {'name': 'Lucy', 'age': 16, 'grade': 98}] print(type(eventList ...

  8. 【记录】使用在线KMS激活Office系列

    摘要 (有能力的请支持正版office) 网上一些激活工具可能捆绑了木马.病毒.使用激活工具有风险.使用在线KMS来激活则没有这个风险. 找到你的office安装目录 已管理员身份运行cmd输入:cd ...

  9. C# groupby 应用小技巧

    这两天感冒了,导致大脑无法有效运转,一个朋友问我,groupby 怎么给list 分组,然后再将其中一个字段组合起来,恩,觉得很简单,结果才发现,自己的脑子真的是不够用了: 恩,其实是想写其他的,但是 ...

  10. zabbix3.4监控Linux客户端

    环境准备 zabbix-server IP:192.168.1.242 nds-server  IP:192.168.1.202 web-server IP:192.168.1.203 客户端部署 关 ...