(有问题 )I - Standard Free2play

You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height h, and there is a moving platform on each height x from 1 to h.

Each platform is either hidden inside the cliff or moved out. At first, there are n moved out platforms on heights p1,p2,…,pn. The platform on height h is moved out (and the character is initially standing there).

If you character is standing on some moved out platform on height x, then he can pull a special lever, which switches the state of two platforms: on height x and x−1. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.

Your character is quite fragile, so it can safely fall from the height no more than 2. In other words falling from the platform x to platform x−2 is okay, but falling from x to x−3 (or lower) is certain death.

Sometimes it’s not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height h, which is unaffected by the crystals). After being used, the crystal disappears.

What is the minimum number of magic crystal you need to buy to safely land on the 0 ground level?

Input
The first line contains one integer q (1≤q≤100) — the number of queries. Each query contains two lines and is independent of all other queries.

The first line of each query contains two integers h and n (1≤h≤109, 1≤n≤min(h,2⋅105)) — the height of the cliff and the number of moved out platforms.

The second line contains n integers p1,p2,…,pn (h=p1>p2>⋯>pn≥1) — the corresponding moved out platforms in the descending order of their heights.

The sum of n over all queries does not exceed 2⋅105.

Output
For each query print one integer — the minimum number of magic crystals you have to spend to safely come down on the ground level (with height 0).

Example
Input
4
3 2
3 1
8 6
8 7 6 5 3 2
9 6
9 8 5 4 3 1
1 1
1
Output
0
1
2
0

刚开始这个题读了好久才看明白
题意:就是你从山上往下跳,高度差<=2,你站在板子上,你可以控制你所站的板子的伸缩,缩你就下落,但是你所处的高度x上,那么x-1处的板子会发生于现在状态相反的改变,如果原来缩着,那么它就会伸出,反之。然后你输入高度和那么高度上的板子是伸着的。你的目的就是不能摔死,你还有魔法,来控制板子,问你最少需要使用多少次魔法。
思路:看了别人的博客。1.如果x-2高度处有挡板,那么我们在x处按动开关,x和x-1高度处的挡板都收起,小人恰好落在x-2高度处的挡板,此时站在x-2高度处要考虑的问题又和站在x-1高度处要考虑的问题一样了

2.如果x-2高度处没有挡板,那很显然x和x-1处的挡板收起后小人就嗝屁了,所以我们冲一块钱,让x-1高度处的挡板收起来,然后再按动开关的时候x-1高度处的挡板恰好伸出,小人正好落上去,接下来的操作仍然相同。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
long long s[5001], a[5001][5001];
int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++)
	{
		long long t; cin >> t;
		s[i] = s[i - 1] + t;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			if (i - m >= 0)
				a[i][j] = max(a[i - 1][j], a[i - m][j - 1] + s[i] - s[i - m]);
		}
	}
	cout << a[n][k];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值