#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int functh(int, int *, int *);
int functs(int, int *, int *);
int main() {
int n, m, ch = INT_MAX, cs = INT_MAX, i, j;
cin >> n >> m;
int costh[n], costs[m];//切割价格,最多横切n-1竖切m-1
int rech[n + 1], recs[m + 1]; //记录某个长度的最优割法,横n,竖m
memset(rech, 0x3f, sizeof(int) * (n + 1));
memset(recs, 0x3f, sizeof(int) * (m + 1));
for ( i = 1; i <= n - 1; i++) {
cin >> costh[i];
}
for ( j = 1; j <= m - 1; j++) {
cin >> costs[j];
}
ch = functh(n, costh, rech);
cs = functs(m, costs, recs);
cout << ch + cs *n << endl;
return 0;
}
int functh(int n, int *p, int *pp) {
int cut;
if (n == 1)
return 0;
if (n == 2)
return p[1];
int &cost = pp[n];
if (cost != 1061109567)
return cost;
for (int i = 1; i <= n - 1; i++) {
cut = p[i];
cost = min(cost, cut + functh(i, p, pp) + functh(n - i, p, pp));
}
return cost;
}
int functs(int n, int *p, int *pp) {
int cut;
if (n == 1)
return 0;
if (n == 2)
return p[1];
int &cost = pp[n];
if (cost != 1061109567)
return cost;
for (int i = 1; i <= n - 1; i++) {
cut = p[i];
cost = min(cost, cut + functs(i, p, pp) + functs(n - i, p, pp));
}
return cost;
}
为什么编译失败了呢,在dev上明明是正常的(泪奔