hdu 5067(暴力搜索)
Harry And Dig Machine
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 852 Accepted Submission(s): 348
we all know, Harry Porter learns magic at Hogwarts School. However,
learning magical knowledge alone is insufficient to become a great
magician. Sometimes, Harry also has to gain knowledge from other certain
subjects, such as language, mathematics, English, and even algorithm.
Dumbledore,
the headmaster of Hogwarts, is planning to construct a new teaching
building in his school. The area he selects can be considered as an n*m
grid, some (but no more than ten) cells of which might contain stones.
We should remove the stones there in order to save place for the
teaching building. However, the stones might be useful, so we just move
them to the top-left cell. Taking it into account that Harry learned how
to operate dig machine in Lanxiang School several years ago, Dumbledore
decides to let him do this job and wants it done as quickly as
possible. Harry needs one unit time to move his dig machine from one
cell to the adjacent one. Yet skilled as he is, it takes no time for him
to move stones into or out of the dig machine, which is big enough to
carry infinite stones. Given Harry and his dig machine at the top-left
cell in the beginning, if he wants to optimize his work, what is the
minimal time Harry needs to finish it?
For each test case, there are two integers n and m.(1≤n,m≤50).
The next n line, each line contains m integer. The j-th number of ith line a[i][j] means there are a[i][j] stones on the jth cell of the ith line.( 0≤a[i][j]≤100 , and no more than 10 of a[i][j] will be positive integer).
0 0 0
0 100 0
0 0 0
2 2
1 1
1 1
4
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int INF = ;
struct Point
{
int x,y;
} p[];
int n,m,res,cnt;
int graph[][];
bool vis[];
void dfs(int x,int dept,int ans)
{
vis[x] = true;
if(ans>res) return ; ///剪枝
if(dept==cnt-)
{
ans += graph[x][]; ///走回去
res = min(res,ans);
return ;
}
for(int i=; i<cnt; i++)
{
if(!vis[i]&&graph[x][i]!=INF&&x!=i)
{
dfs(i,dept+,ans+graph[x][i]);
vis[i] = false;
}
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
cnt = ;
int v;
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
scanf("%d",&v);
if(i==&&j==)
{
p[cnt].x = i,p[cnt++].y=j;
}
else if(v)
{
p[cnt].x = i,p[cnt++].y=j;
}
}
}
for(int i=; i<cnt; i++)
{
for(int j=; j<cnt; j++)
{
if(i==j)graph[i][j] = ;
else graph[i][j] =INF;
}
}
for(int i=; i<cnt; i++)
{
for(int j=i+; j<cnt; j++)
{
graph[i][j] = graph[j][i] = abs(p[i].x-p[j].x)+abs(p[i].y-p[j].y);
}
}
/*for(int i=0; i<cnt; i++)
{
for(int j=0; j<cnt; j++)
{
printf("%d ",graph[i][j]);
}
printf("\n");
}*/
memset(vis,false,sizeof(vis));
res = INF;
vis[] = true;
dfs(,,);
printf("%d\n",res);
}
return ;
}
hdu 5067(暴力搜索)的更多相关文章
- hdu 4740 The Donkey of Gui Zhou(暴力搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...
- HDU 3131 One…Two…Five! (暴力搜索)
题目链接:pid=3131">HDU 3131 One-Two-Five! (暴力搜索) 题意:给出一串数字,要求用加,减,乘,除(5/2=2)连接(计算无优先级:5+3*6=8*6= ...
- hdu 1427 速算24点 dfs暴力搜索
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem De ...
- ACM 暴力搜索题 题目整理
UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...
- HDU 5067 Harry And Dig Machine(状压DP)(TSP问题)
题目地址:pid=5067">HDU 5067 经典的TSP旅行商问题模型. 状压DP. 先分别预处理出来每两个石子堆的距离.然后将题目转化成10个城市每一个城市至少经过一次的最短时间 ...
- 随手练——洛谷-P1151(枚举与暴力搜索)
枚举 #include <iostream> using namespace std; int main() { ; cin >> k; ; i < ; i++) { ) ...
- HDU - 5067 / HDU - 5418 TSP
集合表示多用[0,n)表示方法 HDU - 5067 经典TSP,每个顶点恰经过一次最优 #include<bits/stdc++.h> #define rep(i,j,k) for(in ...
- 枚举进程——暴力搜索内存(Ring0)
上面说过了隐藏进程,这篇博客我们就简单描述一下暴力搜索进程. 一个进程要运行,必然会加载到内存中,断链隐藏进程只是把EPROCESS从链表上摘除了,但它还是驻留在内存中的.这样我们就有了找到它的方法. ...
- HDU 5067 Harry And Dig Machine(状压dp)
HDU 5067 Harry And Dig Machine 思路:因为点才10个,在加上一个起点,处理出每一个点之间的曼哈顿距离,然后用状压dp搞,状态表示为: dp[i][s],表示在i位置.走过 ...
随机推荐
- Windows Server 2012 新特性:IPAM的配置
Windows Server 2012 中的 IPAM 是一个新增的内置框架,用于发现.监视.审核和管理企业网络上使用的 IP 地址空间.IPAM 可以对运行动态主机配置协议 (DHCP) 和域名服务 ...
- Win Server 8中的利器:微软在线备份服务
微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑,是吧?但是微软确实这么做了. 微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑 ...
- ueditor搭建图片服务器
最近用使用富文本编辑器,之前一直使用kindeditor和eWebEditor来着,有同事给推荐说使用百度推出的Ueditor,所以咯,自己新项目就将它引进来了,这里说一下心得, 说实话,Uedito ...
- Pytest+allure+jenkins生成测试报告
allure集成jenkins下载地址.下载相关版本的allure包 http://updates.jenkins-ci.org/download/plugins/allure-jenkins-plu ...
- 【转载】Unity3d UnityEditor编辑器定制和开发插件
在阅读本教程之前,你需要对Unity的操作流程有一些基础的认识,并且最好了解内置的GUI系统如何使用. 如何让编辑器运行你的代码 Unity3D可以通过事件触发来执行你的编辑器代码,但是我们需要一些编 ...
- JavaScript里面之dom操作
1.dom之选择元素 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- hadoop 客户的的使用
${HADOOP_HOME}/bin/hadoop job Usage: JobClient <command> <args> [-submit <job-file> ...
- Spring 学习笔记(二)—— IOC 容器(BeanFactory)
使用Spring IoC容器后,容器会自动对被管理对象进行初始化并完成对象之间的依赖关系的维护,在被管理对象中无须调用Spring的API. 为了实现IoC功能,Spring提供了两个访问接口: or ...
- Mifare简介
Mifare简介 MIFARE是NXP的知名品牌,是一个应用广泛的非接触式IC产品(13.56MHz非接触性辨识技术),一个典型的通信距离为10厘米,在全球有40多个不同的应用领域.有2.6亿个读写器 ...
- 应用交付工程师Troubleshooting经验分享
应用交付工程师Troubleshooting经验分享 来源:http://blog.51cto.com/virtualadc/1188328 来源:http://blog.51cto.com/virt ...