3.15 复试训练

题目:1.8皇后·改

问题描述

规则同8皇后问题,但是棋盘上每格都有一个数字,要求八皇后所在格子数字之和最大。

输入说明

一个8*8的棋盘。

数据规模和约定

棋盘上的数字范围0~99

输出说明

所能得到的最大数字和

输入范例

1 2 3 4 5 6 7 8

9 10 11 12 13 14 15 16

17 18 19 20 21 22 23 24

25 26 27 28 29 30 31 32

33 34 35 36 37 38 39 40

41 42 43 44 45 46 47 48

48 50 51 52 53 54 55 56

57 58 59 60 61 62 63 64

输出范例

260

个人总结:

1.8皇后就是删去对角线,对角线分别用坐标和和坐标差表示。深搜到深度就和最大值比较大小

cpp 复制代码
#include <iostream>
#include <algorithm>
using namespace std;

int board[8][8];
bool col[8] = {false};
bool diag1[15] = {false};
bool diag2[15] = {false};
int max_sum = 0;

void dfs(int row, int current_sum) {
    if (row == 8) {
        max_sum = max(max_sum, current_sum);
        return;
    }

    for (int c = 0; c < 8; c++) {
        int d1 = row - c + 7;
        int d2 = row + c;
        
        if (!col[c] && !diag1[d1] && !diag2[d2]) {
            col[c] = true;
            diag1[d1] = true;
            diag2[d2] = true;
            
            dfs(row + 1, current_sum + board[row][c]);
            
            col[c] = false;
            diag1[d1] = false;
            diag2[d2] = false;
        }
    }
}

int main() {
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            cin >> board[i][j];
        }
    }

    dfs(0, 0);
    cout << max_sum << endl;

    return 0;
}

Solid state storage (sometimes called flash memory) stores data in erasable, rewritable circuitry. A memory card is a flat, solid state storage medium commonly used to transfer files from digital cameras and media players to computers. A solid state drive (SSD) is a package of flash memory that can be used as a substitute for a hard disk drive. A USB flash drive is a portable storage device that plugs directly into a computer's system unit using a built-in USB connector.

固态存储(也称作闪存)可擦写、可编程的电路中存储数据的存储设备。存储卡 是一种扁平的固态存储介质,通常用于将数码照相机和媒体播放器中的文件传输至电脑。固态硬盘 (SSD) 是一组闪存芯片的封装体,可用作硬盘驱动器(HDD)的替代装置。U 盘是一种便携式存储设备,通过其内置的 USB 接口直接与电脑主机相连。

To function, hardware requires physical connections that allow components to communicate and interact. A bus provides a common interconnected system composed of a group of wires or circuitry that coordinates and moves information between the internal parts of a computer. A computer bus consists of two channels: one that the CPU uses to locate data,called the address bus, and another to send the data to that address, called the data bus. A bus is characterized by two features: how much information it can manipulate at one time, called the bus width, and how quickly it can transfer these data.

要正常工作,硬件需要物理连接,使各个部件能够通信并相互作用。总线 提供了一套通用的互联系统,由一组导线或电路组成,用于在计算机内部部件之间协调并传输信息。计算机总线包含两个通道:一个供 CPU 用于定位数据,称为地址总线 ;另一个用于将数据传送到该地址,称为数据总线 。总线有两个特征:一次能处理的信息量,称为总线宽度;以及传输这些数据的速度。

A serial connection is a wire or set of wires used to transfer information from the CPU to an external device such as a mouse, keyboard, modem, scanner, and some types of printers. This type of connection transfers only one piece of data at a time, and is therefore slow. The advantage of using a serial connection is that it provides effective connections over long distances.

串行连接是一根或一组导线,用于在中央处理器与外部设备之间传输信息,例如鼠标、键盘、调制解调器、扫描仪和部分打印机。这种连接方式一次只能传输一位数据,因此速度较慢。串行连接的优点是可以在长距离下实现稳定有效的连接。

相关推荐
j_xxx404_2 小时前
力扣:525.连续数组和1314.矩阵区域和(二维前缀和)
算法·leetcode·矩阵
23.2 小时前
【Java】Arrays工具类——数组操作终极指南
java·算法·面试
Sunsets_Red2 小时前
模意义下及同余的公式整理
c语言·c++·数学·算法·c#·数论·信息学竞赛
计算机安禾2 小时前
【C语言程序设计】第27篇:递归函数原理与实例分析
c语言·开发语言·数据结构·c++·算法·蓝桥杯·visual studio
無限進步D2 小时前
C++ 万能头
开发语言·c++·算法·蓝桥杯·竞赛·万能头
qq_418101772 小时前
C++中的状态模式
开发语言·c++·算法
weixin_307779132 小时前
构建健壮的XML文档抓取与摘要流水线:Requests + urllib3.Retry + lxml 实践
xml·开发语言·python·算法·性能优化
如何原谅奋力过但无声2 小时前
【力扣-Python-74】搜索二维矩阵(middle)
数据结构·python·算法·leetcode·矩阵
咱就是说不配啊2 小时前
3.16打卡day30
数据结构·c++·算法