2019年第十届蓝桥杯C/C++ 省赛B组真题第一题组队

多次验证目前CSDN上发的DFS的基本都是错误的代码,跑不出正确结果。于是写了一个最傻的遍历代码。
在这里插入图片描述
在这里插入图片描述

#include<stdio.h>
#include<stdlib.h>
#define max(a,b) ((a) > (b) ? (a) : (b))
int Score[20][5]={	97,90,0,0,0,
					92,85,96,0,0,
					0,0,0,0,93,
					0,0,0,80,86,
					89,83,97,0,0,
					82,86,0,0,0,
					0,0,0,87,90,
					0,97,96,0,0,
					0,0,89,0,0,
					95,99,0,0,0,
					0,0,96,97,0,
					0,0,0,93,98,
					94,91,0,0,0,
					0,83,87,0,0,
					0,0,98,97,98,
					0,0,0,93,86,
					98,83,99,98,81,
					93,87,92,96,98,
					0,0,0,89,92,
					0,99,96,95,81
					};

int used[20];
int sum = 0;
int sum_max = 0;
int a,b,c,d,e = 0;

int main()
{
	for(a=0;a<20;a++)
	{
		sum+=Score[a][0];
		for(b=0;b<20;b++)
		{
			if(a!=b)
			{
				sum+=Score[b][1];
				for(c=0;c<20;c++)
				{
					if(a!=c&&b!=c)
					{
						sum+=Score[c][2];
						for(d=0;d<20;d++)
						{
							if(d!=c&&d!=b&&d!=a)
							{
								sum+=Score[d][3];
								for(e=0;e<20;e++)
								{
									if(e!=d&&e!=c&&e!=b&&e!=a)
									{
										sum+=Score[e][4];
										sum_max = max(sum_max,sum);
										sum-=Score[e][4];
									}
								}
								sum-=Score[d][3];
							}
						}
						sum-=Score[c][2];
					}
				}
				sum-=Score[b][1];
			}
		}
		sum-=Score[a][0];
	}
	printf("%d",sum_max);
	return 0;
}
发布了4 篇原创文章 · 获赞 2 · 访问量 161

猜你喜欢

转载自blog.csdn.net/weixin_43680772/article/details/104946972