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.

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

相关推荐
吃着火锅x唱着歌9 分钟前
LeetCode 962.最大宽度坡
算法·leetcode·职场和发展
无限进步_19 分钟前
【C++】C++11的类功能增强与STL变化
java·前端·数据结构·c++·后端·算法
WL_Aurora26 分钟前
Python 算法基础篇之排序算法(一):冒泡、选择、插入
python·算法·排序算法
凌波粒28 分钟前
LeetCode--257. 二叉树的所有路径(二叉树)
算法·leetcode·职场和发展
AI算法沐枫29 分钟前
大一学生如何入门机器学习,深度学习,学习顺序如何?
人工智能·python·深度学习·学习·线性代数·算法·机器学习
codealy35 分钟前
Rust 核心理论: 高并发与异步(三)
算法·rust
日月云棠43 分钟前
JAVA数据结构与算法 - 基础:常用集合简述
java·算法
TYKJ02343 分钟前
带宽100M但传输只有30M?你的服务器可能该换TCP算法了
后端·算法
SilentSamsara43 分钟前
运算符重载:让自定义对象支持 +、[]、in 操作
开发语言·python·算法·青少年编程·pycharm
日月云棠1 小时前
JAVA数据结构与算法 - 基础:BlockingQueue
java·算法