题目例如以下:

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. C# 读取IE缓存文件(1)

    using System; using System.Runtime.InteropServices; namespace Common { public class IECache { [DllIm ...

  2. Tomcat通过配置一个虚拟路径管理web工程

    关于虚拟路径.学问javaweb训练课程,如今,鉴于这种情况下老师. 当我们的项目,当在不同的文件夹项目.我们如何使用tomcat去管理web工程. 教师提出的解决方案是 使用虚拟路径方式,并按照实施 ...

  3. FZU 1686 龙之谜 重复覆盖

    兑换0,1模型,如.注意,数据的范围 #include <stdio.h> #include <string.h> #include <iostream> #inc ...

  4. Cocos2dx-3.1.1 冒险01----&gt; 文件夹结构、新项目project创建并执行

    windows开发环境:window7.vs2012.python2.7.6 Cocos2d-x 3.1.1的完整文件夹例如以下:比起曾经的2.x的版本号来说分类更规范了 watermark/2/te ...

  5. WPF学习(2)XAML

    XAML(eXtensible Application Markup Language,可扩展应用程序标记语言)是一种声明式的编程语言,遵循XML的语法.WPF使用XAML来设计UI具有易用性.高效性 ...

  6. QR代码简单

    QR代码(Quick Response Code, 高速响应码)属于二维矩阵码在一个.由DENSO(日本电装)公司开发,由JIS和ISO将其标准化. QR码分为两种模式:模式1.模式2.当中.模式1相 ...

  7. JUnit使用参数测试和一组测试

    JUnit该参数测试和一组测试使用简单 参数测试 作为替代阵列int a0,a1,a2喜欢,当测试加法assertEquals(3.0, h.add(1, 2), 0.1);相当于声明一个变量,要測试 ...

  8. vs2013提交github代码

    vs2013的新特性之一就是可以方便的通过集成的git工具管理git代码.今天简单给大家演示 在github新建仓库 复制仓库地址 克隆仓库到本地(这一步非常重要,只有顺利获取github的code, ...

  9. WPF六个控制概述

    在线演示:http://v.youku.com/v_show/id_XNzA0NjU1Mjk2.html 清晰版视频+代码下载:http://115.com/lb/5lbcftnrfo9s 一.简单介 ...

  10. CodeForces 441 A. Valera and Antique Items

    纯粹练JAVA.... A. Valera and Antique Items time limit per test 1 second memory limit per test 256 megab ...