UVA 167 The Sultan's Successors (带权8皇后)

面对一个8x8的棋盘,每个格子上有1到99的数值,任务是在满足皇后不互相攻击的条件下放置8个皇后,使得所选格子上的数值之和尽可能大。

    The Sultan of Nubia has no children, so she has decided that the country will be split into up to kseparate parts on her death and each part will be inherited by whoever performs best at some test. Itis possible for any individual to inherit more than one or indeed all of the portions. To ensure thatonly highly intelligent people eventually become her successors, the Sultan has devised an ingenioustest. In a large hall filled with the splash of fountains and the delicate scent of incense have beenplaced k chessboards. Each chessboard has numbers in the range 1 to 99 written on each square and issupplied with 8 jewelled chess queens. The task facing each potential successor is to place the 8 queenson the chess board in such a way that no queen threatens another one, and so that the numbers onthe squares thus selected sum to a number at least as high as one already chosen by the Sultan. (Forthose unfamiliar with the rules of chess, this implies that each row and column of the board containsexactly one queen, and each diagonal contains no more than one.)

    Write a program that will read in the number and details of the chessboards and determine thehighest scores possible for each board under these conditions. (You know that the Sultan is both agood chess player and a good mathematician and you suspect that her score is the best attainable.)

InputInput

    will consist of k (the number of boards), on a line by itself, followed by k sets of 64 numbers,each set consisting of eight lines of eight numbers. Each number will be a positive integer less than100. There will never be more than 20 boards.

Output

    Output will consist of k numbers consisting of your k scores, each score on a line by itself and rightjustified in a field 5 characters wide.

Sample Input 

1

    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


Sample Output


260


题意:

第一行一个整数k,代表k组输入。

每组输入一个8*8的矩阵的各个位置上权值。

求一种8皇后的摆法(皇后无法相互攻击),使其权值和最大。


思路:


枚举所有摆法,求权值最大值。(注意:答案输出靠右,占5个字符)

看了一下位运算n皇后解法,试试水,详见代码


代码:

#include<stdio.h>

#define For(a,b,c) for(int a = b; a <= c; a++)

//maxn存储当前最大值,v存储权值,limit存储没有皇后时可摆放的位置
int maxn, v[10][10], limit = (1 << 8)-1;

//row某一列无法占据,ld左斜,rd右斜,sum当前权值,cnt当前层数
void n_queue(int row, int ld, int rd, int sum, int cnt)
{
    if(cnt == 8)
    {
        maxn = sum > maxn ? sum : maxn;
        return;
    }

    //abl存储能放棋子位置,a枚举每个能放棋子的位置,index存储放在第几位
    int abl = limit & (~(row | ld | rd)), a, index;

    while(abl)
    {
        a = abl & (~abl + 1);
        abl -= a;
        index = 0;
        while(a>>index) index++;
        //因为摆法对称所以 sum传参也可以是sum + v[cnt+1][index]
        n_queue(row | a, (ld | a) << 1, (rd | a) >> 1, sum + v[cnt+1][8-index+1], cnt+1);
    }

}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        For(i,1,8)
        {
            For(j,1,8)
            {
                scanf("%d",&v[i][j]);
            }
        }
        maxn = 0;
        n_queue(0,0,0,0,0);
        printf("%5.d\n",maxn);//注意输出格式控制
    }
    return 0;
}


内容概要:本文提出了一种基于改进扩散模型的高海拔地区新能源高波动出力场景生成方法,并提供了完整的Python代码实现。该方法针对高海拔地区风能、光伏等新能源出力波动剧烈、不确定性高的特点,通过优化扩散模型的结构与训练策略,有效捕捉历史据的概率分布特征与时序相关性,从而生成高质量、多样化的出力场景。文中详细阐述了模型的学推导、网络架构设计、损失函优化及采样算法改进,并通过实验证明其在拟合精度、场景多样性与稳定性方面优于传统生成模型,为电力系统在高比例新能源接入下的规划、调度与风险评估提供了可靠的场景输入支持。; 适合人群:具备一定Python编程能力和机器学习基础,从事新能源发电预测、电力系统分析、智能优化、场景生成等方向研究的科研人员、高校研究生及工程技术人员。; 使用场景及目标:①用于高海拔地区风电、光伏出力的不确定性建模与多场景生成;②支撑含高渗透率新能源的电力系统随机优化调度、鲁棒决策与风险评估;③为相关学术研究、论文复现与算法改进提供可运行的技术方案与代码基础; 阅读建议:建议读者结合所提供的完整资源(代码、据集、说明文档)进行实践操作,重点关注扩散模型的前向加噪与反向去噪过程的设计细节,以及如何将其适配于新能源时序据的生成任务,通过参调优与对比实验深入理解模型的生成机制与性能边界。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值