//前提:背包里不同的金币袋使用后生成的总金币数满足需求量
//需求:计算使用最少的金币袋达到需求量。
//分析:不一定每种金币袋都有
//useCountList 为每种金币袋使用后增加的金币数量列表,例如大袋金币袋可以增加 1万个金币
//countList 用户道具背包中每种金币袋的数量列表
// target 目标值
// dic 下标,数量
//递归函数 列表 游标
private void CheckGoldMaxCount(List<int> useCountList, List<int> countList, int target, Dictionary<int, int> dic, int index = 0)
{
//如果目标值为0 ,说明已完成最优计算
if (target == 0)
{
return;
}
//如果不存在某种金币袋,其他对应数量和增加金币置0;
// 游标加1 进入下一层计算
if (countList[index] == 0)
{
index++;
Debug.Log(" index 315 " + index);
CheckGoldMaxCount(useCountList, countList, target, dic, index);
}
else
{
//用户该类型所有数量仍小于目标值
if (countList[index] * useCountList[index] < target)
{
target = target - countList[inde
unity 使用背包多种货币物品
于 2022-01-21 22:46:45 首次发布