cpp
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int f[101][25];
int main()
{
int a[101]={0,534, 386, 319, 692, 169, 338, 521, 713, 640, 692, 969, 362, 311, 349, 308, 357, 515, 140, 591, 216,57, 252, 575, 630, 95, 274, 328, 614, 18, 605, 17, 980, 166, 112, 997, 37, 584, 64, 442, 495,821, 459, 453, 597, 187, 734, 827, 950, 679, 78, 769, 661, 452, 983, 356, 217, 394, 342, 697, 878,475, 250, 468, 33, 966, 742, 436, 343, 255, 944, 588, 734, 540, 508, 779, 881, 153, 928, 764, 703,459, 840, 949, 500, 648, 163, 547, 780, 749, 132, 546, 199, 701, 448, 265, 263, 87, 45, 828, 634};
for(int i=1;i<=100;i++){
int d=a[i]%24;
f[i][d]=max(f[i][d],max(f[i-1][0]+a[i],f[i-1][d]));
for(int x=1;x<24;x++){
if(f[i-1][x])f[i][(x+d)%24]=max(f[i][(x+d)%24],max(f[i-1][x]+a[i],f[i-1][(x+d)%24]));
else f[i][(x+d)%24]=f[i-1][(x+d)%24];
}
}
cout<<f[100][0]<<endl;
return 0;
}
来源:第十六届蓝桥杯模拟赛(第二期)c++答案与代码_小蓝准备请自己的朋友吃饭。小蓝朋友很多,最终吃饭的人总数达 2024 人(包括他自己-CSDN博客