The Sultan of Nubia has no children, so she has decided that the country will be split into up tokseparate parts on her death and each part will be inherited by whoever performs best at some test. It
is possible for any individual to inherit more than one or indeed all of the portions. To ensure that only highly intelligent people eventually become her successors, the Sultan has devised an ingenious test. In a large hall filled with the splash of fountains
and the delicate scent of incense have been placedkchessboards. Each chessboard has numbers in the range 1 to 99 written on each square and is supplied with 8 jewelled chess queens. The task facing each potential successor is to place the 8 queens
on the chess board in such a way that no queen threatens another one, and so that the numbers on the squares thus selected sum to a number at least as high as one already chosen by the Sultan. (For those unfamiliar with the rules of chess, this implies that
each row and column of the board contains exactly 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 the highest scores possible for each board under these conditions. (You know that the Sultan is both a good chess player
and a good mathematician and you suspect that her score is the best attainable.)
Input
Input will consist ofk(the number of boards), on a line by itself, followed byksets of 64 numbers, each set consisting of eight lines of eight numbers. Each number will be a positive integer
less than 100. There will never be more than 20 boards.
Output
Output will consist ofknumbers consisting of yourkscores, each score on a line by itself and right justified 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
一道典型的变异八皇后问题,每个节点带权值了。
#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
int arry[10][10],vis[3][20];
int maxnum;
void dfs(int pos,int num)
{
int i,j;
if(pos==8)
{
if(num>maxnum)
{
maxnum=num;
}
return;
}
else
{
for(i=0;i<8;i++)
{
if(!vis[0][i]&&!vis[1][i+pos]&&!vis[2][pos-i+8])
{
vis[0][i]=vis[1][i+pos]=vis[2][pos-i+8]=1;
dfs(pos+1,num+arry[pos][i]);
vis[0][i]=vis[1][i+pos]=vis[2][pos-i+8]=0;
}
}
}
}
int main()
{
int n;
cin>>n;
while(n--)
{
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
cin>>arry[i][j];
}
}
memset(vis,0,sizeof(vis));
maxnum=0;
dfs(0,0);
cout<<setw(5)<<maxnum<<endl;
}
return 0;
}
分享到:
相关推荐
资源分类:Python库 所属语言:Python 资源全名:sultan-0.3.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Sultan POS的主要目标是小型市场,并且能够在Raspberry Pi上运行。特征联网(使用websocket) 多价项目类别供应商多用户和权限数据库SQLite / MySQL 销售报告物品销售报告资金报告使用平均值计算保证金客户资料库...
sultan-kernel-celox:适用于Samsung Skyrocket(SGH-I727)和Samsung Hercules(SGH-T989)的AOSP内核,基于官方的Samsung Jelly Bean内核源代码发布,并重新基于CAF jb_1.9.6
- POJ 1130 - The Sultan's Successors(背包问题变体) **相关知识点**: - 状态定义与转移方程的建立 - 多维DP与一维DP的转换技巧 - DP算法的时间复杂度分析 - 背包问题的不同类型及其解法 #### 四、总结 通过...
"餐厅:Sultan是使用Bootstrap构建的动态,适合移动设备的Web应用程序",这个标题表明我们正在讨论一个基于Bootstrap框架的Web应用,该应用专门为餐饮业设计,特别是餐厅业务。Sultan是一个动态网站,意味着它具有...
【SULTAN-4TH-JUNE】项目是一个与Java编程相关的资源包,其名称可能代表一个特定的项目、挑战或教程,日期“4TH-JUNE”可能是该项目的发布或更新日期。由于没有提供更详细的信息,我们将从Java编程语言的角度出发,...
Anis Koubaa目前担任沙特阿拉伯Prince Sultan University教授,并同时在葡萄牙波尔图的Polytechnic Institute of Porto担任CISTER/INESC-TEC研究员。他专注于嵌入式系统、机器人学和物联网技术的研究,发表了多篇高...
资源分类:Python库 所属语言:Python 资源全名:sultan-0.3.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
SpringPetClinic样品申请 通过一些图表了解Spring Petclinic应用程序 在本地运行诊所 Petclinic是使用构建的应用程序。 您可以构建一个jar文件并从命令行运行它: ...cd spring-petclinic ./mvnw package ...
本卷的编辑Anis Koubaa来自沙特阿拉伯的Riyadh的Prince Sultan University,同时也是葡萄牙波尔图ISEP理工学院CISTER/INESC-TEC研究中心的成员,这说明了本书的国际性和合作性质。 本卷的ISBN为978-3-319-26052-5,...
... ...这些组件都是预设计好的,开发者可以根据需求进行调整和自定义,节省了大量的时间和精力。例如,模板中的仪表板可能包含了统计图表,利用JavaScript库如Chart.js或Highcharts来展示数据;表格可能使用了...
Sultan Qaboos university is a young university compared to universities found in the Arabian Gulf region. However, it has an excellent reputation in the ``` - 输出示例: ``` Sultan Qaboos ...
7. **首字母完形填空**:在给定的句子中,考生需根据首字母填写缺失的单词以完成句子,如描述Mysore王国历史的一段话,涉及历史事件和人物,如“Wodeyar dynasty”,“Hyder Ali”和“Tipu Sultan”。 8. **读句子*...
本资料集围绕"Singnal and Image processing basic labs"这一主题,包含了四份实验文档,分别是Lab1_Sultan_Yerumbayev.doc、Lab2_SultanYerumbayev.doc、Lab3_Sultan_yerumbayev.docx和Lab4_Sultan_Yerumbayev.doc...
杰里科(Wadi Al-Qalt,Ain或Tal Sultan和Al-Nwehmeh)和拉马拉(Safa,Turmus Aya和Qibia)。 由于没有对这些地区进行分类研究,因此我们对巴勒斯坦的400个采样菌群进行了统计处理。 此外,分类是根据1979年的...
Sultan等人:监督机器学习算法的决策功能作为加速分子模拟的集体变量,arXiv预印本 使用以下图片可以概括总体思路: 给定开始状态和结束状态中的一些采样,SML算法(例如支持向量机)可以找到一个最大平面,该...