题目例如以下:

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. hdu 4856 Tunnels(bfs+状态压缩)

    题目链接:hdu 4856 Tunnels 题目大意:给定一张图,图上有M个管道,管道给定入口和出口,单向,如今有人想要体验下这M个管道,问最短须要移动的距离,起点未定. 解题思路:首先用bfs处理出 ...

  2. SQL Server -减少代码触发的负担

    触发器是一张表的增删改操作,引起或触发对还有一张表的增删改操作,所以触发器便有3种类型.各自是deleted触发器.Update触发器,insert触发器 触发器又依据替换原来的增删改操作,还是在原来 ...

  3. Oracle Product Hub / Product Lifecycle Management / Product Information Management / Advanced Produc

    In this Document   Goal   Solution   1. Master List showing sample code for APIs in Product Data Hub ...

  4. 学习vi和vim编辑(3):一个简单的文本编辑器(2)

    然后文章,继续评论vi编辑简单的文本编辑命令. 本文主要是删除的文字.复制,运动命令. 删除文本: 正如上一篇文章中讲过的,对于删除命令("d")也具有"(command ...

  5. ADN中国队参加微软Kinect他赢得了全国比赛三等奖,我们的创意项目与团队Kinect于Naviswork虚拟之旅

    以下是我的英语写了一个简短的总结,直接贴出来. 让我们知道我们在这参加Hackathon That's an exciting Hackathon for me and also China team ...

  6. Grant的时候报错的解决:Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES)

    mysql> grant all on *.* to 'root'@'192.168.1.1' identified by 'password'; ERROR 1045 (28000): Acc ...

  7. 简单搜索dfs, 简单的修剪搜索

    选择最合适的语言做一个项目是非常重要的.但,熟练的掌握自己的武器,这也是非常重要的. ========================================================= ...

  8. RDIFramework.NET ━ .NET高速信息系统开发框架钜献 V2.9 版本震撼发布

    RDIFramework.NET ━ .NET高速信息化系统开发框架钜献 V2.9 版本号震撼公布  全新体验.全新感觉.2015钜献! 继上个版本号"RDIFramework.NET V2 ...

  9. [HAOI2005]路由问题,第二短路

    [问题描写叙述]     X城有一个含有N个节点的通信网络,在通信中,我们往往关心信息从一个节点I传输到节点J的最短路径.遗憾的是.因为种种原因,线路中总有一些节点会出故障,因此在传输中要避开故障节点 ...

  10. 【白注意】Windows XP 大胆拥抱Linux在系统中所遇到的问题

    Windows XP至4月8日本将不再是微软官方技术支持.虽然仍可以继续使用,但他们大部分的风险.可一不留神被黑客攻击.似向下,Linux这也是一个不错的选择. 或许很多文章开始教你如何迁移,您,迁移 ...