UVA 1291 - Dance Dance Revolution(dp)

本文介绍了一款名为“Dance Dance Revolution”的游戏,并提出了一个算法问题:如何计算完成特定舞蹈序列所需的最少体力消耗。通过动态规划方法解决该问题,实现了玩家在游戏中的最优策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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:

\epsfbox{p2031.eps}

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 $ \rightarrow$ 2 $ \rightarrow$ 2 $ \rightarrow$ 4. His feet may stays on (point 0, point 0) $ \rightarrow$ (0, 1) $ \rightarrow$ (2, 1) $ \rightarrow$ (2, 1) $ \rightarrow$ (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

题意:题意转自:http://blog.youkuaiyun.com/shuangde800/article/details/9876957


如上图,这是一个跳舞机,初始状态两个脚都在0,  状态表示为(0, 0), 然后跳舞机会给你一系列舞步方向,例如2,3,4,2,3.......

每次你必须选择一只脚移动到对应数字方向的各格子上。

例如从初始状态(0,0),要移到1, 可以选择左脚或者右脚移上去,对应的状态为(1, 0), (0,1)

有一个限制,除了初始状态可以是(0, 0),之后的两只脚就不能再同时在一个格子上!

移动脚要耗费体力, 从0移动到其它各自都是耗费2, 从1,2,3,4之间,如果是移动到相邻的格子,比如1->2, 1->4, 3->2, 4->3,耗费体力3

如果是移动到对面的格子,比如1->3, 2->4,耗费体力4。

如果某一步,停止不动,耗费体力1,现在给一串方向,问最少用多少体力可以完成这些动作?

思路:dp,先预处理出cost数组,dp[i][j][k]表示第i步,左脚放j右脚放k时候的最小耗费,dp[i][j][k] = min(dp[i - 1][l][k] + cost[l][j], dp[i - 1][j][r] + cost[k][r]);

注意判断左脚右脚放在一起的情况。

代码:

#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
const int N = 1005;
int cost[5][5], num[N], dp[N][5][5], n;

void init() {
	cost[1][1] = cost[2][2] = cost[3][3] = cost[4][4] = 1;
	cost[0][1] = cost[0][2] = cost[0][3] = cost[0][4] = 2;
	cost[1][2] = cost[2][1] = cost[1][4] = cost[4][1] = cost[2][3] = cost[3][2] = cost[3][4] = cost[4][3] = 3;
	cost[1][3] = cost[3][1] = cost[2][4] = cost[4][2] = 4;
}

int solve() {
	int ans = INF;
	memset(dp, INF, sizeof(dp));
	dp[0][0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= 4; j++) {
			for (int k = 0; k <= 4; k++) {
				if (j == k) continue;
				if (j == num[i]) {
					for (int l = 0; l <= 4; l++) {
						if (l == k && l != 0) continue;
						dp[i][j][k] = min(dp[i][j][k], dp[i - 1][l][k] + cost[l][j]);
					}
				}
				if (k == num[i]) {
					for (int r = 0; r <= 4; r++) {
						if (r == j && r != 0) continue;
						dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][r] + cost[r][k]);
					}
				}
				if (i == n)
					ans = min(ans, dp[i][j][k]);
			}
		}
	}
	return ans;
}

int main() {
	init();
	while (~scanf("%d", &num[1]) && num[1]) {
		n = 1;
		while (~scanf("%d", &num[++n]) && num[n]);
		printf("%d\n", solve());
	}
	return 0;
}


内容概要:本文详细探讨了基于MATLAB/SIMULINK的多载波无线通信系统仿真及性能分析,重点研究了以OFDM为代表的多载波技术。文章首先介绍了OFDM的基本原理和系统组成,随后通过仿真平台分析了不同调制方式的抗干扰性能、信道估计算法对系统性能的影响以及同步技术的实现与分析。文中提供了详细的MATLAB代码实现,涵盖OFDM系统的基本仿真、信道估计算法比较、同步算法实现和不同调制方式的性能比较。此外,还讨论了信道特征、OFDM关键技术、信道估计、同步技术和系统级仿真架构,并提出了未来的改进方向,如深度学习增强、混合波形设计和硬件加速方案。; 适合人群:具备无线通信基础知识,尤其是对OFDM技术有一定了解的研究人员和技术人员;从事无线通信系统设计与开发的工程师;高校通信工程专业的高年级本科生和研究生。; 使用场景及目标:①理解OFDM系统的工作原理及其在多径信道环境下的性能表现;②掌握MATLAB/SIMULINK在无线通信系统仿真中的应用;③评估不同调制方式、信道估计算法和同步算法的优劣;④为实际OFDM系统的设计和优化提供理论依据和技术支持。; 其他说明:本文不仅提供了详细的理论分析,还附带了大量的MATLAB代码示例,便于读者动手实践。建议读者在学习过程中结合代码进行调试和实验,以加深对OFDM技术的理解。此外,文中还涉及了一些最新的研究方向和技术趋势,如AI增强和毫米波通信,为读者提供了更广阔的视野。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值