点击打开链接

这道题,明显就是八皇后问题 就是给你一个8*8的方格 问你找到八皇后占位置的 总和的最大值 这个题其实很简单  可以先开3个数组 来标记  一个标记  列  两个来标记 对角线 然后这道题深搜  就行了  其实对于行来说 直接就是 一行搜下来就行(因为一行肯定有一个皇后 来站着 )  还有个坑点就是 我们这个要求 按着右边输出 右边输出就要(“%5d”) 我具体也不知道为什么 但是听学长们说 要求 ~~~ 行吧

#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<iostream>
#include<set>
#include<map>
#include<string.h>
using namespace std;
int mapp[10][10];
int bj[5][1000];
int sum=0;
void dfs(int x,int y)
{if(x==8){sum=max(y,sum);return;}for(int i=0; i<8; i++){if(!bj[0][i]&&!bj[1][x+i]&&!bj[2][x-i+7]){bj[0][i]=1;bj[1][x+i]=1;bj[2][x-i+7]=1;dfs(x+1,y+mapp[x][i]);bj[0][i]=0;bj[1][x+i]=0;bj[2][x-i+7]=0;}}
}
int main()
{int t;scanf("%d",&t);while(t--){sum=0;memset(bj,0,sizeof(bj));for(int i=0; i<8; i++){for(int j=0; j<8; j++){scanf("%d",&mapp[i][j]);}}dfs(0,0);printf("%5d\n",sum);}return 0;
}

The Sultan's Successors相关推荐

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

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

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

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

  3. UVA The Sultan's Successors

    题目如下: The Sultan's Successors  The Sultan of Nubia has no children, so she has decided that thecount ...

  4. uva 167 The Sultan's Successors

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

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

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

  6. The Sultan's Successors UVA - 167

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

  7. 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 ...

  8. 38行代码AC——UVA-167The Sultan‘s Successors(八皇后问题,附视频讲解)

    最近备考蓝桥,学习到递归模块,从最基本的八皇后及其变种开始刷起(如果可以穿越,我一定要抓到发明递归的那个人,然后把他干掉,造福后世的算法er,). 题目大意 一个人,没孩子,要在死前分割财产,然后出了 ...

  9. HDU1642 UVA167 UVALive5227 The Sultan's Successors题解

    代码来源:DeathYmz AC的C++语言程序如下: #include<iostream> #include<cstdio> #include<cstring> ...

最新文章

  1. 如何让mysql的自动递增的字段重新从1开始呢?(
  2. 经历就是财富——总结我的26岁
  3. mysql为什么要转es_MySQL用得好好的,为什么要转ES?
  4. C语言变长数组 struct中char data[0]的用法
  5. Qt工作笔记-在Graphics上写文本(QGraphicsSimpleTextItem与QGraphicsTextItem的基本使用)
  6. phpcms v9输出内容过滤html代码 - 代码篇
  7. c语言编写界面图形表示,「分享」C语言如何编写图形界面
  8. MongoDB 索引操作详解
  9. authware链接html文件,authorware是什么软件?
  10. 逻辑学中的思维规律:同一律,不矛盾律,排中律,充足理由律
  11. Android解决手机图片压缩后旋转问题
  12. SAP License:ERP系统实施价格是多少?
  13. 课程设计:波形发生器
  14. IT界最伟大的十位人物
  15. Java基础-数组01
  16. 静静的分析华为Mate X的部分“亮点”,静静的围观它装逼!
  17. 代码的坏味道之十三 :Speculative Generality(夸夸其谈未来性)
  18. 数据字典的作用/用途:是数据流程图的补充!4个主要条目:数据项,数据处理(逻辑功能及其算法),数据存储,数据流条目
  19. LeetCode.1005-K次取负数组和最大(Maximize Sum Of Array After K Negations)
  20. VRTK4开发VR2:射线

热门文章

  1. JS数据交互:动态从数据库中获取数据填充Select
  2. 23.打印由*号组成的三角形图案
  3. 解决注册Github邮箱用qq邮箱无法收到验证码的问题
  4. 数学建模案例--基于微分方程的酒后驾车问题浅析
  5. 基于httpx和pyside2的哔哩哔哩(bilibili)-视频下载程序
  6. 小米手机6的主要参数与特性
  7. 一作3篇SCI认定A类博士!享100万安家费+30万科启!三年副教授待遇+2K/月津贴!...
  8. java 及 js 格式化金额 三位一撇(逗号)
  9. UI设计:模仿淘宝App首页
  10. macOS上的汇编入门(五)——第一个汇编程序