【AtCoder】【DP】Colorful Slimes(AG004)

本文探讨了在有限资源下高效获取特定颜色史莱姆的策略,通过分析两种操作成本,提出了一种动态规划方法来最小化获取指定数量史莱姆的总代价。

题意:

有N种颜色的史莱姆,每种颜色有无线多个史莱姆。每次可以花Ai的代价抓一只没有的史莱姆,或者是花费x的代价让已经有的所有的史莱姆的颜色+1(颜色为N的变为1)。

数据范围:

1<=N<=2*10^3 1<=x<=10^9

思路:

因为可以让其他的史莱姆通过变换颜色来得到当前我们想要的史莱姆,所以说一种颜色的史莱姆显然是要被多次捕捉的。然后,我们可以发现,第二种操作的全局的移动次数实际上是移动次数最大的那只史莱姆的移动次数。因为不可能一只史莱姆的初始颜色相同并且满足颜色+1的次数也相同,那么上述性质是成立的。
我最开始想到的是一个n^3的DP,也就是枚举一个最大的颜色+1的次数,然后在这个次数限制下,枚举一种颜色,再在限制范围内枚举,找到得到这种颜色花费最少的方法,但是太低效了。
可以考虑从小到大枚举颜色+1的次数,然后当前对于某种颜色就可以利用之前已经算出来的信息(因为颜色+1次数 < 当前颜色+1次数的途径是合法的),只对于当前这一次新多出来的转移方式取min,就可以求得得到当前这种颜色的最小代价了。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 2000
#define INF 1000000000000000000LL
using namespace std;
typedef long long LL;
int N;
LL b[MAXN+5],a[MAXN+5],x;
int main()
{
//	freopen("slime.in","r",stdin);
//	freopen("slime.out","w",stdout);
	scanf("%d %lld",&N,&x);
	for(int i=0;i<N;i++)
		scanf("%lld",&a[i]);
	fill(b,b+N,INF);
	LL ans=INF;
	for(int mv=0;mv<N;mv++)
	{
		LL ansn=0;
		for(int i=0;i<N;i++)
			b[i]=min(b[i],a[(i-mv+N)%N]);//只考虑当前的最远的转移,利用之前的信息
		for(int i=0;i<N;i++)
			ansn+=b[i];
		ansn+=mv*x;
		ans=min(ans,ansn);
	}
	printf("%lld\n",ans);
	return 0;
}

代码还是比较简单的。

Merging slimes is a common mechanic in various games, especially those with a resource - management or idle - game aspect. Here are some general steps and information about merging slimes in different contexts: ### In a typical slime - merging game - **Gather slimes**: Usually, slimes are obtained at the start of the game or through certain actions like completing missions, opening chests, or waiting for them to spawn in the game environment. - **Place slimes**: Put the slimes on a merging platform or area in the game interface. This is often a dedicated space where the merging action can take place. - **Merge similar slimes**: Select two slimes of the same level and type. When they are combined, they will fuse into a single slime of a higher level. For example, two level - 1 slimes might merge into a level - 2 slime. - **Upgrade and progress**: As you merge slimes to higher levels, you can unlock new abilities, gain more in - game currency, or progress to new areas of the game. ### In programming (simulating slime merging) If you want to simulate the slime - merging process in a programming language, here is a simple Python example: ```python class Slime: def __init__(self, level): self.level = level def merge(self, other_slime): if self.level == other_slime.level: return Slime(self.level + 1) return None # Example usage slime1 = Slime(1) slime2 = Slime(1) merged_slime = slime1.merge(slime2) if merged_slime: print(f"Merged into a level {merged_slime.level} slime.") else: print("Cannot merge these slimes.") ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值