题目如下:

The Sultan's Successors 

The Sultan of Nubia has no children, so she has decided that thecountry will be split into up to k separate parts on her death andeach part will be inherited by whoever performs best at some test. Itis possible for any individual to inherit more than one or indeed allof the portions. To ensure that only highly intelligent peopleeventually become her successors, the Sultan has devised an ingenioustest. In a large hall filled with the splash of fountains and thedelicate scent of incense have been placed k chessboards. Eachchessboard has numbers in the range 1 to 99 written on each square andis supplied with 8 jewelled chess queens. The task facing eachpotential successor is to place the 8 queens on the chess board insuch a way that no queen threatens another one, and so that thenumbers on the squares thus selected sum to a number at least as highas one already chosen by the Sultan. (For those unfamiliar with therules of chess, this implies that each row and column of the boardcontains exactly one queen, and each diagonal contains no more thanone.)

Write a program that will read in the number and details of thechessboards and determine the highest scores possible for each boardunder these conditions. (You know that the Sultan is both a good chessplayer and a good mathematician and you suspect that her score is thebest attainable.)

Input

Input 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 linesof 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, eachscore on a line by itself and right justified in a field 5 characterswide.

Sample input

11  2  3  4  5  6  7  89 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

经典的八皇后问题,白书上有详细讲解。这里不过是多了一个求所在格子数的和的最大值,只需求出一种情况后维护最大值即可。

AC的代码如下:

#include using namespace std;
int G[8][8];
int vis[5][30];
int MAX;
void dfs(int cur,int sum)
{
if(cur==8)
{
if(MAX>k;
while(k--)
{
for(int i=0; i<8; i++)
for(int j=0; j<8; j++)
cin>>G[i][j];
memset(vis,0,sizeof vis);
MAX=0;
dfs(0,0);
printf("%5d\n",MAX);
}
return 0;
}

UVA The Sultan's Successors相关推荐

  1. uva 167 The Sultan's Successors

    题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108& ...

  2. UVA167【The Sultan‘s Successors】(递归与回溯、8皇后问题)

    链接:UVA167[The Sultan's Successors] 题目描述: The Sultan of Nubia has no children, so she has decided tha ...

  3. The Sultan's Successors (八皇后)DFS

    The Sultan's Successors 原题链接https://vjudge.net/contest/345248#problem/F 八皇后问题,既在8*8的棋盘中放置8个皇后,每行,每列, ...

  4. The Sultan's Successors (八皇后)

    The Sultan's Successors(八皇后问题) The Sultan of Nubia has no children, so she has decided that the coun ...

  5. The Sultan's Successors UVA - 167

    //很久以前做的了,当时WA,一直没找到错误...然后今天看了下...发现就是每次开始新一轮年的时候没哟初始化....... The Sultan of Nubia has no children, ...

  6. Uva 167 The Sultan's Successors(dfs)

    题目链接:Uva 167 思路分析:八皇后问题,采用回溯法解决问题. 代码如下: #include <iostream> #include <string.h> using n ...

  7. UVA 167(The Sultan's Successors)八皇后回溯

    题意 输入8x8的棋盘 在棋盘上放置8个皇后 输出8个皇后位置对应数字之和的最大值 回溯,一年前做的题目,竟然又碰到了,之前没学过dfs,对着题解思考了很长时间... 粗心的我,写错了一个变量名,查了 ...

  8. UVA 167 - The Sultan‘s Successors

    题目大意:八皇后问题,每个格子有分数,皇后放置在格子上则得到分数,问怎么放置八皇后总分数最高. 解题思路:回溯,小紫里讲的挺清楚的,只要在达成条件时,将八个位置的分数加起来最后得到最高分输出就可以了. ...

  9. 167 The Sultan's Successors

    原题: The Sultan of Nubia has no children, so she has decided that the country will be split into up t ...

最新文章

  1. 将虚拟机的版本改为1.6的方法
  2. Flink的滚动策略
  3. 友盟分享成功之后没有提示信息的解决
  4. [转].NET 开源项目 Polly 介绍
  5. FFmpeg non-existing PPS 0 referenced问题描述
  6. 苹果与高通联合抢占 5G!
  7. LeetCode 526. Beautiful Arrangement
  8. String与字节数组转换
  9. 胡萝卜,是鸡蛋,还是咖啡豆
  10. python链接mysql的代码
  11. 网络七层协议的形象说明
  12. mysql frm_mysqlfrm初步使用
  13. 张宝杰:将IT创造价值进行到底的秘诀
  14. !include: could not find: nsProcess.nsh
  15. FFOS 1.3 settings usb tethering 流程
  16. SAP 凭证跳号分析
  17. ubuntu16.04开机自动挂载nas盘
  18. HTML基础(P24-P44)
  19. 【R生态】普鲁克分析(Procrustes Analysis)
  20. (operational-transformations)ot算法两个字符串如何生成ot操作转换的工具

热门文章

  1. 什么是C语言及C语言的特点
  2. 长沙计算机学院王进,王进教授
  3. matlab读入三维点云数据斯坦福兔子
  4. CSS 样式属性大全
  5. 人工智能概念类知识点总结
  6. QQ邮箱验证码登录(移动端邮箱验证登录)
  7. 常见的管道命令:sort、uniq、tr、cut
  8. 向大家隆重介绍Impel计划
  9. Java开发——IDEA
  10. 时钟(CLOCK)置换算法