【无标题】

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博客

相关推荐
apcipot_rain20 分钟前
C++转Java日记(05)
java·开发语言·c++
apcipot_rain9 小时前
C++转Java日记(04)
java·开发语言·c++
NEFU_Jyj9 小时前
牛客周赛R168
算法
WL学习笔记11 小时前
vector模拟实现
c++
蜗牛一步步往上爬14 小时前
第十六章 C++语言在深度学习中的应用
开发语言·c++·深度学习
likexuec16 小时前
数据结构(2)
数据结构
Navigator_Z17 小时前
LeetCode //C - 1317. Convert Integer to the Sum of Two No-Zero Integers
c语言·算法·leetcode
wo_jack17 小时前
C++ 入门笔记(十六):第16课 vector 模拟实现十问十答 —— 从三指针到迭代器失效
c++·后端·面试·stl·vector
D e re k ZH18 小时前
C++ 标准库算法全景指南
数据结构·c++·算法