HDU1642 UVA167 UVALive5227 The Sultan's Successors题解
代码来源: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题解相关推荐
- UVA167【The Sultan‘s Successors】(递归与回溯、8皇后问题)
链接:UVA167[The Sultan's Successors] 题目描述: The Sultan of Nubia has no children, so she has decided tha ...
- uva 167 The Sultan's Successors
题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108& ...
- The Sultan's Successors (八皇后)DFS
The Sultan's Successors 原题链接https://vjudge.net/contest/345248#problem/F 八皇后问题,既在8*8的棋盘中放置8个皇后,每行,每列, ...
- UVA The Sultan's Successors
题目如下: The Sultan's Successors The Sultan of Nubia has no children, so she has decided that thecount ...
- The Sultan's Successors (八皇后)
The Sultan's Successors(八皇后问题) The Sultan of Nubia has no children, so she has decided that the coun ...
- The Sultan's Successors UVA - 167
//很久以前做的了,当时WA,一直没找到错误...然后今天看了下...发现就是每次开始新一轮年的时候没哟初始化....... The Sultan of Nubia has no children, ...
- 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 ...
- UVA 167(The Sultan's Successors)八皇后回溯
题意 输入8x8的棋盘 在棋盘上放置8个皇后 输出8个皇后位置对应数字之和的最大值 回溯,一年前做的题目,竟然又碰到了,之前没学过dfs,对着题解思考了很长时间... 粗心的我,写错了一个变量名,查了 ...
- 38行代码AC——UVA-167The Sultan‘s Successors(八皇后问题,附视频讲解)
最近备考蓝桥,学习到递归模块,从最基本的八皇后及其变种开始刷起(如果可以穿越,我一定要抓到发明递归的那个人,然后把他干掉,造福后世的算法er,). 题目大意 一个人,没孩子,要在死前分割财产,然后出了 ...
最新文章
- pytorchviz visdom 可视化 pytorch
- 四月青少年编程组队学习(Python一级)Task01
- Nature:学术造假者瑟瑟发抖,论文图像查重AI技术重拳出击!
- MATLAB图像取点操作
- 高级技巧之Lambda表达式
- java微信支付必要参数_微信支付 开发账号体系各参数详解
- IntelliJ IDEA下的使用git
- Mac 实现keras网络模型可视化【conda】
- sql语句的执行过程和优化
- android go解析json,Go 关于Json通用解析
- php为什么要使用静态方法,为什么PHP在对象上下文中使用静态方法?
- Docker容器和本机之间的文件传输
- 用于微服务和ML解决方案管道的消息队列(Kafka和Zookeeper)
- NSString 与 Unicode
- 华为崔景龙:FNV是下一代MBB网络演进的技术驱动
- 在excel中求算风向和风速范围的函数,用origin做风向玫瑰图
- c语言 sub(),C语言考试试题
- LeetCode题解(1818):绝对差值和(Python)
- 新概念51单片机c语言教程考试题,新概念51单片机C语言教程例题.doc
- 网络无法访问互联网是什么原因
热门文章
- 4个不错的Flash开源项目
- 关于AIR 应用程序沙箱
- C#Socket同步异步通讯总结笔记
- 计算机被格式化怎么找回资料,电脑文档被格式化,怎么恢复格式化文档
- python爬虫项目描述怎么写_爬虫项目咋写,爬取什么样的数据可以作为项目写在简历上?...
- SpringBoot集成 Shiro
- Python 之 函数进阶
- HDFS读流程,写流程,放置策略
- js接收php 回调,JS callback回调函数的使用(附代码)
- weui上传组件的图片封装到formdata_自定义toast-ui富文本组件的图片黏贴上传