求助大神,这个该怎么改
#include <bits/stdc++.h>using namespace std;
int a = {{0, 0,0,0,0,0},
{0, 9,2,4,15, 9},
{0, 6,5,12, 4,2},
{0, 11, 7,13, 4,17},
{0, 19, 11, 15, 8,9}};
bool v;
map<int, string> mp;
struct sta {
int sum, two;
pair<int, int> c;
vector<pair<int, int> > one;
};
vector<sta> sch;
void dfs(int u, sta now) {
if (u == 5) {
if (!sch.empty() && sch.back().sum > now.sum)sch.clear();
if (sch.empty() || sch.back().sum == now.sum)
sch.push_back(now);
return;
}
if (!sch.empty() && sch.back().sum < now.sum)return;
vector<int> c;
for (int i = 1; i <= 5; i++)if (!v)c.push_back(i);
if (u == 4 && c.size() == 2) {
v] = true, v] = true;
sta nex = now;
nex.two = u;
nex.sum += a] + a];
nex.c = make_pair(c, c);
dfs(u + 1, nex);
v] = false, v] = false;
return;
}
for (int i = 0; i < c.size(); i++) {
sta nex = now;
nex.sum += a];
nex.one.emplace_back(u, c);
v] = true;
dfs(u + 1, nex);
v] = false;
}
for (int i = 0; i < c.size(); i++)
for (int j = i + 1; j < c.size(); j++) {
v] = true, v] = true;
sta nex = now;
nex.two = u;
nex.sum += a] + a];
nex.c = make_pair(c, c);
dfs(u + 1, nex);
v] = false, v] = false;
}
}
int main() {
sta now = {0, 0, {0, 0}, {}};
dfs(1, now);
mp = "甲", mp = "乙", mp = "丙", mp = "丁";
printf("总最小花费时间为:%d\n", sch.back().sum);
for (int i = 0; i < sch.size(); i++) {
cout << "方案" << i + 1 << ":" << endl;
cout << mp.two] << "完成任务:" << (char) ('A' + sch.c.first - 1) << "和"
<< (char) ('A' + sch.c.second - 1) << endl;
for (int j = 0; j < sch.one.size(); j++) {
cout << mp.one.first] << "完成任务:" << (char) ('A' + sch.one.second - 1) << endl;
}
puts("");
}
return 0;
}
你这个emplace_back是想要干嘛?{:10_269:}
xiaosi4081 发表于 2021-6-15 18:24
你这个emplace_back是想要干嘛?
我从csdn上抄的,看不懂{:5_99:},运行后报错了! 啦啦啦95426 发表于 2021-6-15 19:03
我从csdn上抄的,看不懂,运行后报错了!
emplace_back 是另一种 push_back 不过emplace_back会原地构造对象,不触发拷贝构造和移动构造
页:
[1]