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.

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

相关推荐
To_OC6 小时前
LC 131 分割回文串:刚学回溯时,我连怎么切字符串都想不明白
javascript·算法·leetcode
旖-旎7 小时前
LeetCode 518:零钱兑换||(完全背包)—— 题解
c++·算法·leetcode·动态规划·背包问题
To_OC7 小时前
LC 42 接雨水:暴力超时卡半天?前后缀数组一用就通了
javascript·算法·leetcode
delishcomcn8 小时前
AI视觉识别+分切算法:电化铝缺陷检测与裁切一体化解锁
人工智能·算法
触底反弹8 小时前
深入理解大模型采样:Temperature、Top-K、Top-P 的原理与实战
人工智能·算法·面试
雪碧聊技术9 小时前
力扣 LCR 091. 粉刷房子 —— 动态规划入门详解
算法·动态规划
CV-Climber11 小时前
检索技术的实际应用
人工智能·算法
hhzz12 小时前
Tiger AI Platform平台中增加人脸识别功能
图像处理·人工智能·算法·计算机视觉·大模型
从零开始的代码生活_13 小时前
C++ 继承详解:访问控制、对象模型、菱形继承与设计取舍
开发语言·c++·后端·学习·算法