Uva 167 The Sultan's Successors
来源:互联网 发布:网络剧受众群体. 编辑:程序博客网 时间:2024/06/01 09:38
简单的八皇后问题,水过~~
注意输出格式就可以~~
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<algorithm>
using namespace std;
int vis[3][16];
int chess[8][8],maxx;
void Init()
{
maxx = 0;
for(int i = 0;i < 3;i++)
memset(vis[i],0,sizeof(vis[i]));
for(int i = 0;i < 8;i++)
for(int j = 0;j < 8;j++)
scanf("%d",&chess[i][j]);
}
void Search(int cur,int score)
{
int i,j;
if(cur == 8) {if(score > maxx) maxx = score;}
else for(int i = 0;i < 8;i++)
{
if(!vis[0][i] && !vis[1][cur+i] && !vis[2][cur-i+8])
{
vis[0][i] = vis[1][cur+i] = vis[2][cur-i+8] = 1;
Search(cur+1,score + chess[i][cur]);
vis[0][i] = vis[1][cur+i] = vis[2][cur-i+8] = 0;
}
}
}
int main()
{
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int cases;
scanf("%d",&cases);
while(cases--)
{
Init();
Search(0,0);
printf("%5d\n",maxx);
}
return 0;
}
- UVa 167 - The Sultan's Successors
- Uva 167 The Sultan's Successors
- uva 167 - The Sultan's Successors
- uva 167 - The Sultan's Successors
- UVa 167 - The Sultan's Successors
- Uva-167-The Sultan's Successors
- uva 167 - The Sultan's Successors
- UVa 167 - The Sultan's Successors
- uva 167 - The Sultan's Successors
- uva 167 The Sultan's Successors
- uva 167 The Sultan's Successors
- UVa 167 - The Sultan's Successors
- UVa 167 - The Sultan's Successors
- UVa 167 - The Sultan's Successors
- UVA 167 - The Sultan's Successors
- UVA - 167 The Sultan's Successors
- UVA - 167 The Sultan's Successors
- uva 167 The Sultan's Successors 搜索
- Android之SharedPreferences对参数数据的存取
- 生存之根本
- 对面向对象的一些思考
- 嵌入式Linux之我行——RamDisk块设备驱动实例开发讲解
- Java实训笔记(四)
- Uva 167 The Sultan's Successors
- 网络篇——七层协议、四层协议、TCP、HTTP、SOCKET、长短连接
- fgets函数与fputs函数
- Uva 10344 23 out of 5
- Spring系列(3/2)---交互的改进
- QQ通信原理及QQ是怎么穿透内网进行通信的?(关于P2P)
- 静态数组实现循环队列
- Apt-get详解及新立德
- 动态数组实现循环队列