#include <stdio.h>
#include <string.h>
#define MAX_DAYS 4
#define NUM_SPOTS 4
typedef struct {
char name[10];
int day;
int score;
} Spot;
void calculateMaxValue(Spot spots[], int n) {
int dp[MAX_DAYS + 1];
memset(dp, 0, sizeof(dp));
int chosen[MAX_DAYS + 1];
memset(chosen, -1, sizeof(chosen));
for (int i = 0; i < n; ++i) {
for (int j = MAX_DAYS; j >= spots[i].day; --j) {
if (dp[j] < dp[j - spots[i].day] + spots[i].score) {
dp[j] = dp[j - spots[i].day] + spots[i].score;
chosen[j] = i;
}
}
}
printf("最大评分为: %d\n", dp[MAX_DAYS]);
printf("选择的景点有: \n");
int remainingDays = MAX_DAYS;
while (remainingDays > 0 && chosen[remainingDays] != -1) {
Spot chosenSpot = spots[chosen[remainingDays]];
printf("%s (评分: %d)\n", chosenSpot.name, chosenSpot.score);
remainingDays -= chosenSpot.day;
}
}
int main() {
Spot spots[NUM_SPOTS] = {
{"故宫", 1, 7},
{"颐和园", 2, 8},
{"长城", 3, 9},
{"天坛", 1, 6}
};
calculateMaxValue(spots, NUM_SPOTS);
return 0;
}