题目例如以下:

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

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

经典的八皇后问题,白书上有具体解说。这里只是是多了一个求所在格子数的和的最大值,仅仅需求出一种情况后维护最大值就可以。

AC的代码例如以下:

UVA The Sultan's Successors的更多相关文章

  1. uva 167 - The Sultan's Successors(典型的八皇后问题)

    这道题是典型的八皇后问题,刘汝佳书上有具体的解说. 代码的实现例如以下: #include <stdio.h> #include <string.h> #include < ...

  2. UVA 816 - Abbott&#39;s Revenge(BFS)

    UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=59 ...

  3. uva 11825 Hackers&#39; Crackdown (状压dp,子集枚举)

    题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...

  4. UVA 10831 - Gerg&#39;s Cake(数论)

    UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p.问有没有存在x^2 % p = a的解 思路:求出勒让德标记.推断假设大于等于0,就是有解,小于0无解 代码: ...

  5. UVA 12103 - Leonardo&#39;s Notebook(数论置换群)

    UVA 12103 - Leonardo's Notebook 题目链接 题意:给定一个字母置换B.求是否存在A使得A^2=B 思路:随意一个长为 L 的置换的k次幂,会把自己分裂成gcd(L,k) ...

  6. UVA 11774 - Doom&#39;s Day(规律)

    UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / ...

  7. uva 10831 - Gerg&#39;s Cake(勒让德符号)

    题目链接:uva 10831 - Gerg's Cake 题目大意:给定a和p.p为素数,问说是否存在x,使得x2≡a%p 解题思路:勒让德记号,推断ap−12≡1%p #include <cs ...

  8. UVA 11825 - Hackers&#39; Crackdown 状态压缩 dp 枚举子集

    UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...

  9. uva 11178 Morley&#39;s Theorem(计算几何-点和直线)

    Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states tha ...

随机推荐

  1. ArcMap合并之路 -- 该段路合并成一个完整的路

    #1: 用 Arctoolbox\Data Management Tools\Generalization\dissolve 工具 #2: Options:dissolve field 项选" ...

  2. C++学习笔记1--基础知识

    #include <iomanip> setpresition(int n); 设置输出精度浮点数是n. [goto声明] goto也被称为无条件分支语句购买勇于改变运行顺序的声明.got ...

  3. 我有DIY一Android遥控-所有开源

    我有DIY一Android遥控-所有开源 1.试用 记得宋宝华在「设备驱动开发具体解释」提出一个这种理论「软件和硬件互相渗透对方的领地」,这次证明还是确实是这样,使用上层APP软件加上简单的更为简单的 ...

  4. iOS如何添加照片模拟器(附带诉讼)

    刚開始做图片选择时,使用了最笨的办法给iphone模拟器添加照片. 方法一:首先打开safari.然后找到图片.点击图片,保存到本地(iphone): 方法二:拖动本地计算机的随意一张照片到iphon ...

  5. Android决议具体解释

    1.Android手机常见的分辨率 WVGA:800x480 FWVGA:854x480 QHD:960x540 720P:1280x720(SD.standard definition,SD) 10 ...

  6. ZOJ 3820 Building Fire Stations

    题意: 树上找两个点  使得其它点到这两点随意一点的距离的最大值最小 思路: 最大值最小  想到二分  在二分的基础上判定这个最大值是否可能 怎样判定这个问题就是怎样选那两个点的问题  非常明显  我 ...

  7. Reorder List [leetcode] 这两种思路

    第一个想法随着vector保存全部Node* 表拼接出来 void reorderList(ListNode *head) { vector<ListNode*> content; Lis ...

  8. opencv-阈值处理

    从原理:http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/imgproc/threshold/threshold.html 目标: ...

  9. 房费制VB版本(一个)——系统分析

          首先.我们先回答两个个问题:         1.机房收费系统"是什么"?         2.机房收费系统应该"干什么"?        我的回答 ...

  10. Java回合阵列List

    package com.mine.practice.arrtolist; import java.util.ArrayList; import java.util.Arrays; import jav ...