#include <iostream>
#include <vector>
using namespace std;
struct Spot {
string name;
int time;
int score;
};
void printOptimizedTravelPlan(const vector<Spot>& spots, int totalDays) {
int n = spots.size();
vector<vector<int>> dp(n + 1,
vector<int>(totalDays + 1, 0));
vector<vector<bool>> choice(
n + 1, vector<bool>(totalDays + 1, false));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= totalDays; j++) {
int currTime = spots[i - 1].time;
int currScore = spots[i - 1].score;
if (currTime > j) {
dp[i][j] = dp[i - 1][j];
choice[i][j] = false;
} else {
int scoreWithSpot =
dp[i - 1][j - currTime] + currScore;
int scoreWithoutSpot = dp[i - 1][j];
if (scoreWithSpot > scoreWithoutSpot) {
dp[i][j] = scoreWithSpot;
choice[i][j] = true;
} else {
dp[i][j] = scoreWithoutSpot;
choice[i][j] = false;
}
}
}
}
int remainingDays = totalDays;
vector<string> selectedSpots;
for (int i = n; i >= 1; i--) {
if (choice[i][remainingDays]) {
selectedSpots.push_back(spots[i - 1].name);
remainingDays -= spots[i - 1].time;
}
}
cout << "最优化旅游计划: " << endl;
cout << "总评分: " << dp[n][totalDays] << endl;
cout << "选择的景点: ";
for (auto it = selectedSpots.rbegin(); it != selectedSpots.rend(); ++it) {
cout << *it << " ";
}
cout << endl;
}
int main() {
vector<Spot> spots = {
{"故宫", 1, 7}, {"颐和园", 2, 8}, {"长城", 3, 9}, {"天坛", 1, 6}};
int totalDays = 4;
printOptimizedTravelPlan(spots, totalDays);
return 0;
}