因此,我正在尝试解决动态编程练习,该练习与计算最短时间相关,同时获得一些在Wormix游戏中完成任务的点数。但是任务确实不重要。问题是在使用动态编程原理创建二维数组时,我有两个例外。
因此,int ** dynamic
的第二维数不是恒定的pointSum
而且它也不能变形
"int (*)[1]"
至"int **"
第一个如何处理,第二个意味着什么?
#include <iostream>
#include <cmath>
using namespace std;
struct Wormix {
int point;
int time;
};
static int missionsAvaliable;
static int pointsNeeded;
int point;
int time;
static Wormix * missions;
int number1;
int number2;
int pointSum = 0;
int timeSum = 0;
int main() {
cin >> missionsAvaliable >> pointsNeeded;
missions = new Wormix[missionsAvaliable];
for (int i = 0; i < missionsAvaliable; i++) {
cin >> number1 >> number2;
pointSum += number1;
timeSum += number2;
missions[i] = Wormix{ number1, number2 };
}
if (pointSum < pointsNeeded) {
cout<<(-1);
return 0;
}
if (pointSum == pointsNeeded) {
cout<<(timeSum);
return 0;
}
pointSum-=pointsNeeded+1;
int ** dynamic = new int[missionsAvaliable + 1][pointSum];
return 0;
}