代码来源:DeathYmz

AC的C++语言程序如下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
//八皇后+回溯
int ans;
int C[8];
int boards[8][8],vis[3][2*8];
void search(int cur)//问题只要求八个   cur行i列
{if(cur==8) {int s=0;for(int i=0;i<8;i++)s+=boards[i][C[i]];if(ans<s) ans=s;}///走到这,所有皇后不冲突else for(int i=0;i<8;i++){if(!vis[0][i]&&!vis[1][cur+i]&&!vis[2][cur-i+8])//判断 {C[cur]=i;vis[0][i]=vis[1][cur+i]=vis[2][cur-i+8]=1;search(cur+1);vis[0][i]=vis[1][cur+i]=vis[2][cur-i+8]=0;}}
}
int main()
{int k;scanf("%d",&k);while(k--){ans=0;memset(boards,0,sizeof(boards));memset(vis,0,sizeof(vis));for(int i=0;i<8;i++)for(int j=0;j<8;j++)scanf("%d",&boards[i][j]);search(0);printf("%5d\n",ans);//注意 }return 0;
} 

HDU1642 UVA167 UVALive5227 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. uva 167 The Sultan's Successors

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

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

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

  4. UVA The Sultan's Successors

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

  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. UVA 167(The Sultan's Successors)八皇后回溯

    题意 输入8x8的棋盘 在棋盘上放置8个皇后 输出8个皇后位置对应数字之和的最大值 回溯,一年前做的题目,竟然又碰到了,之前没学过dfs,对着题解思考了很长时间... 粗心的我,写错了一个变量名,查了 ...

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

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

最新文章

  1. pytorchviz visdom 可视化 pytorch
  2. 四月青少年编程组队学习(Python一级)Task01
  3. Nature:学术造假者瑟瑟发抖,论文图像查重AI技术重拳出击!
  4. MATLAB图像取点操作
  5. 高级技巧之Lambda表达式
  6. java微信支付必要参数_微信支付 开发账号体系各参数详解
  7. IntelliJ IDEA下的使用git
  8. Mac 实现keras网络模型可视化【conda】
  9. sql语句的执行过程和优化
  10. android go解析json,Go 关于Json通用解析
  11. php为什么要使用静态方法,为什么PHP在对象上下文中使用静态方法?
  12. Docker容器和本机之间的文件传输
  13. 用于微服务和ML解决方案管道的消息队列(Kafka和Zookeeper)
  14. NSString 与 Unicode
  15. 华为崔景龙:FNV是下一代MBB网络演进的技术驱动
  16. 在excel中求算风向和风速范围的函数,用origin做风向玫瑰图
  17. c语言 sub(),C语言考试试题
  18. LeetCode题解(1818):绝对差值和(Python)
  19. 新概念51单片机c语言教程考试题,新概念51单片机C语言教程例题.doc
  20. 网络无法访问互联网是什么原因

热门文章

  1. 4个不错的Flash开源项目
  2. 关于AIR 应用程序沙箱
  3. C#Socket同步异步通讯总结笔记
  4. 计算机被格式化怎么找回资料,电脑文档被格式化,怎么恢复格式化文档
  5. python爬虫项目描述怎么写_爬虫项目咋写,爬取什么样的数据可以作为项目写在简历上?...
  6. SpringBoot集成 Shiro
  7. Python 之 函数进阶
  8. HDFS读流程,写流程,放置策略
  9. js接收php 回调,JS callback回调函数的使用(附代码)
  10. weui上传组件的图片封装到formdata_自定义toast-ui富文本组件的图片黏贴上传