UVA The Sultan's Successors
题目例如以下:
| 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的更多相关文章
- uva 167 - The Sultan's Successors(典型的八皇后问题)
这道题是典型的八皇后问题,刘汝佳书上有具体的解说. 代码的实现例如以下: #include <stdio.h> #include <string.h> #include < ...
- UVA 816 - Abbott's Revenge(BFS)
UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=59 ...
- uva 11825 Hackers' Crackdown (状压dp,子集枚举)
题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...
- UVA 10831 - Gerg's Cake(数论)
UVA 10831 - Gerg's Cake 题目链接 题意:说白了就是给定a, p.问有没有存在x^2 % p = a的解 思路:求出勒让德标记.推断假设大于等于0,就是有解,小于0无解 代码: ...
- UVA 12103 - Leonardo's Notebook(数论置换群)
UVA 12103 - Leonardo's Notebook 题目链接 题意:给定一个字母置换B.求是否存在A使得A^2=B 思路:随意一个长为 L 的置换的k次幂,会把自己分裂成gcd(L,k) ...
- UVA 11774 - Doom's Day(规律)
UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / ...
- uva 10831 - Gerg's Cake(勒让德符号)
题目链接:uva 10831 - Gerg's Cake 题目大意:给定a和p.p为素数,问说是否存在x,使得x2≡a%p 解题思路:勒让德记号,推断ap−12≡1%p #include <cs ...
- UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集
UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...
- uva 11178 Morley's Theorem(计算几何-点和直线)
Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states tha ...
随机推荐
- C语言求素数的算法
前言 最后一次是出了素数的问题C语言解决题目(面试),当时用了最粗暴的算法.回来细致參考资料,事实上答案有非常多种: 1,小学生版本号: 推断 x 是否为质数,就从 2 一直算到 x-1. stati ...
- MEF初体验之七:Using Catalogs
MEF特性化编程模型的价值主张之一是通过catalogs动态发现部件的能力.Catalogs允许应用程序很容易地消费那些通过[Export]已经自我注册的exports. Assembly Catal ...
- 第22题 Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
- 如何设置eclipse在默认模式下打开文件
如何设置eclipse在默认模式下打开文件 打开eclipse.选择例如以下:windows --> preferences --> General --> Editors --&g ...
- MessageFormat类别:快速格式化字符串
MessageFormat 获取一组对象,格这些对象的类型,然后格串类型插入的地方的图案. 第一个样例使用静态的方法 MessageFormat.format.它在内部创建一个仅仅使用一次的 Mess ...
- 一张漫画说尽IT开发过程
- Team Foundation Server 2015使用教程--默认团队权限说明
- 分布式中使用Redis实现Session共享(转)
上一篇介绍了如何使用nginx+iis部署一个简单的分布式系统,文章结尾留下了几个问题,其中一个是"如何解决多站点下Session共享".这篇文章将会介绍如何使用Redis,下一篇 ...
- 动态规划,而已! CodeForces 433B - Kuriyama Mirai's Stones
Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from ...
- POJ 2329 (暴力+搜索bfs)
Nearest number - 2 Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3943 Accepted: 1210 De ...