UVA 1291 十四 Dance Dance Revolution
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Mr. White, a fat man, now is crazy about a game named ``Dance, Dance, Revolution". But his dance skill is so poor that he could not dance a dance, even if he dances arduously every time. Does ``DDR" just mean him a perfect method to squander his pounds? No way. He still expects that he will be regarded as ``Terpsichorean White" one day. So he is considering writing a program to plan the movement sequence of his feet, so that he may save his strength on dancing. Now he looks forward to dancing easily instead of sweatily.
``DDR" is a dancing game that requires the dancer to use his feet to tread on the points according to the direction sequence in the game. There are one central point and four side points in the game. Those side points are classified as top, left, bottom and right. For the sake of explanation, we mark them integers. That is, the central point is 0, the top is 1, the left is 2, the bottom is 3, and the right is 4, as the figure below shows:

At the beginning the dancer's two feet stay on the central point. According to the direction sequence, the dancer has to move one of his feet to the special points. For example, if the sequence requires him to move to the top point at first, he may move either of his feet from point 0 to point 1 (Note: Not both of his feet). Also, if the sequence then requires him to move to the bottom point, he may move either of his feet to point 3, regardless whether to use the foot that stays on point 0 or the one that stays on point 1.
There is a strange rule in the game: moving both of his feet to the same point is not allowed. For instance, if the sequence requires the dancer to the bottom point and one of his feet already sta ys on point 3, he should stay the very foot on the same point and tread again, instead of moving the other one to point 3.
After dancing for a long time, Mr. White can calculate how much strength will be consumed when he moves from one point to another. Moving one of his feet from the central point to any side points will consume 2 units of his strength. Moving from one side point to another adjacent side point will consume 3 units, such as from the top point to the left point. Moving from one side point to the opposite side point will consume 4 units, such as from the top point to the bottom point. Yet, if he stays on the same point and tread again, he will use 1 unit.
Assume that the sequence requires Mr. White to move to point 1 2
2
4. His feet may stays on (point 0, point 0)
(0, 1)
(2, 1)
(2, 1)
(2, 4). In this couple of integers, the former number represents the point of his left foot, and the latter represents the point of his right foot. In this way, he has to consume 8 units of his strength. If he tries another pas, he will have to consume much more strength. The 8 units of strength is the least cost.
Input
The input file will consist of a series of direction sequences. Each direction sequence contains a sequence of numbers. Ea ch number should either be 1, 2, 3, or 4, and each represents one of the four directions. A value of 0 in the direction sequence indicates the end of direction sequence. And this value should be excluded from the direction sequence. The input file ends if the sequence contains a single 0.
Output
For each direction sequence, print the least units of strength will be consumed. The result should be a single integer on a line by itself. Any more white spaces or blank lines are not allowable.
Sample Input
- 1 2 2 4 0
- 1 2 3 4 1 2 3 3 4 2 0
- 0
Sample Output
- 8
- 22
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- using namespace std;
- const int inf=0x3f3f3f3f;
- int a[];
- int dp[][][];
- int main()
- {
- int n;
- int i,j,k;
- while(scanf("%d",&a[])!=EOF && a[]!=)
- {
- n=;
- while(a[n]!=)
- {
- n++;
- scanf("%d",&a[n]);
- }
- memset(dp,inf,sizeof(dp));
- dp[][a[]][]=,dp[][][a[]]=;
- for(i=;i<n;i++)
- {
- for(j=;j<=;j++)
- {
- for(k=;k<=;k++)
- {
- if(dp[i-][j][k]<inf)
- {
- int x,y;
- if(a[i]!=k)
- {
- x=abs(a[i]-j);
- if(x==)
- y=;
- else if(x== || x==)
- y=;
- else if(x==)
- y=;
- if(j==)
- y=;
- dp[i][a[i]][k]=min(dp[i][a[i]][k],dp[i-][j][k]+y);
- }
- if(a[i]!=j)
- {
- x=abs(a[i]-k);
- if(x==)
- y=;
- else if(x== || x==)
- y=;
- else if(x==)
- y=;
- if(k==)
- y=;
- dp[i][j][a[i]]=min(dp[i][j][a[i]],dp[i-][j][k]+y);
- }
- }
- }
- }
- }
- int ans=inf;
- for(i=;i<=;i++)
- {
- if(dp[n-][i][a[n-]]<ans)
- ans=dp[n-][i][a[n-]];
- if(dp[n-][a[n-]][i]<ans)
- ans=dp[n-][i][a[n-]];
- }
- printf("%d\n",ans);
- }
- return ;
- }
UVA 1291 十四 Dance Dance Revolution的更多相关文章
- 递推DP UVA 1291 Dance Dance Revolution
题目传送门 题意:给一串跳舞的动作,至少一只脚落到指定的位置,不同的走法有不同的体力消耗,问最小体力消费多少分析:dp[i][j][k] 表示前i个动作,当前状态(j, k)的最小消费,状态转移方程: ...
- [LA] 2031 Dance Dance Revolution
Dance Dance Revolution Time limit: 3.000 seconds Mr. White, a fat man, now is crazy about a game nam ...
- Dance Dance Revolution
今天我们来讲 Dance Dance Revolution这题 本题原网址 注意本题为多组输入输出,直到输入单个零而止(题面有点小问题) 很明显,此题为一道动态规划题(请不要妄想用贪心算法过这题,尽管 ...
- 我的MYSQL学习心得(十四) 备份和恢复
我的MYSQL学习心得(十四) 备份和恢复 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) ...
- 雅虎(yahoo)前端优化十四条军规
第一条.尽可能的减少 HTTP 的请求数 (Make Fewer HTTP Requests ) http请求是要开销的,想办法减少请求数自然可以提高网页速度.常用的方法,合并css,js(将一个页面 ...
- Bootstrap<基础二十四> 缩略图
Bootstrap 缩略图.大多数站点都需要在网格中布局图像.视频.文本等.Bootstrap 通过缩略图为此提供了一种简便的方式.使用 Bootstrap 创建缩略图的步骤如下: 在图像周围添加带有 ...
- Bootstrap<基础十四> 按钮下拉菜单
使用 Bootstrap class 向按钮添加下拉菜单.如需向按钮添加下拉菜单,只需要简单地在在一个 .btn-group 中放置按钮和下拉菜单即可.也可以使用 <span class=&qu ...
- AngularJs的UI组件ui-Bootstrap分享(十四)——Carousel
Carousel指令是用于图片轮播的控件,引入ngTouch模块后可以在移动端使用滑动的方式使用轮播控件. <!DOCTYPE html> <html ng-app="ui ...
- C#编程总结(十四)dynamic
http://www.cnblogs.com/yank/p/4177619.html C#编程总结(十四)dynamic 介绍 Visual C# 2010 引入了一个新类型 dynamic. 该类型 ...
随机推荐
- Oracle中的rownum用法解析
注意:rownum从1开始: 1.rownum按照记录插入时的顺序给记录排序,所以有order by的子句时一定要注意啊! 2.使用时rownum,order by字段是否为主键有什么影响? 3 ...
- [CrunchBang]Linux系统下必要的中文字体
sudo apt-get install ttf-droid ttf-wqy-zenhei xfonts-wqy ttf-wqy-microhei ttf-arphic-ukai ttf-arphic ...
- Sql server analysis service 通过IIS连接时的最大连接数问题
做过SSAS项目的大部分人都应该知道SSAS是可以通过在IIS上建立代理站点的方式来建立远程连接的,这样可以绕过连接到SSAS时需要在同一个域环境下通过域用户来验证的问题,这样即使连接到SSAS的客户 ...
- 四种MySQL存储引擎
前言 数据库存储引擎是数据库底层软件组织,数据库管理系统(DBMS)使用数据引擎进行创建.查询.更新和删除数据.不同的存储引擎提供不同的存储机制.索引技巧.锁定水平等功能,使用不同的存储引擎,还可以 ...
- 图像处理工具包ImagXpress教程:Accusoft不同组件间的图像数据传递
图像处理工具包ImagXpress的开发厂商Accusoft Pegasus旗下有多种图像处理相关的控件,但是这些图像处理控件之间的如何加传递图像数据呢?在ImagXpress 11版本之前,是需要将 ...
- 原生js轮播以及setTimeout和setInterval的理解
下面这个代码是从一个群下载下来的,为了帮助自己理解和学习现在贴出来,与初学者共勉. <!DOCTYPE html> <html> <head> <meta c ...
- iOS直播的技术分析与实现
HTTP Live Streaming直播(iOS直播)技术分析与实现 发布于:2014-05-28 13:30阅读数:12004 HTTP Live Streaming直播(iOS直播)技术分析与实 ...
- React Native学习笔记-1:JSC profiler is not supported.
新建React-Native工程,直接编译运行报错,控制台错误信息如下: 2016-02-22 16:49:47.317 [info][tid:com.facebook.React.JavaScrip ...
- 利用python进行数据分析 (学习笔记)
第一章:准备工作 1.重要的Python库 (1)NumPy:Python科学计算的基础包.功能有:
- 9、Http回顾/Servlet
1 Http回顾 Http协议: 1)http协议: 对浏览器客户端和服务器端之间数据传输的格式规范. 2)http请求:浏览器->服务器端 格式: 请求行(请求方式(GET/POST) 请求资 ...