题目1091:棋盘游戏(DFS)
题目链接:http://ac.jobdu.com/problem.php?pid=1091
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
//
// 1091 棋盘游戏.cpp
// Jobdu
//
// Created by PengFei_Zheng on 04/05/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#define MAX_SIZE 6
//#define debug using namespace std; int n, ans = INT_MAX;
int xStart,yStart,xEnd,yEnd; int map[MAX_SIZE][MAX_SIZE];
bool visited[MAX_SIZE][MAX_SIZE]; int change[][]={{-,,,},{,,-,}}; void DFS(int x, int y, int status, int sum){
int nextX,nextY,cost;
if(sum < ans){
if(x==xEnd && y==yEnd){
ans = sum;
return ;
}
for(int i = ; i < ; i ++){
nextX = x + change[][i];
nextY = y + change[][i];
if(!visited[nextX][nextY] && nextX>= && nextX<MAX_SIZE && nextY>= && nextY<MAX_SIZE){
cost = map[nextX][nextY]*status;
visited[nextX][nextY]=true;
DFS(nextX,nextY,cost%+,sum+cost);//注意参数传递
visited[nextX][nextY]=false;
}
}
}
}
int main(){
#ifdef debug
freopen("/Users/pengfei_zheng/Desktop/input.txt", "r", stdin);
#endif
scanf("%d",&n);
while(n--){
memset(map,,sizeof(map));
for(int i = ; i < MAX_SIZE ; i++){
for(int j = ; j < MAX_SIZE ; j++){
scanf("%d",&map[i][j]);
visited[i][j]=false;
}
}
ans = INT_MAX;
scanf("%d %d %d %d",&xStart,&yStart,&xEnd,&yEnd);
DFS(xStart,yStart,,);
printf("%d\n",ans);
}
return ;
}
/**************************************************************
Problem: 1091
User: zpfbuaa
Language: C++
Result: Accepted
Time:10 ms
Memory:1520 kb
****************************************************************/
题目1091:棋盘游戏(DFS)的更多相关文章
- 九度oj 题目1091:棋盘游戏
题目描述: 有一个6*6的棋盘,每个棋盘上都有一个数值,现在又一个起始位置和终止位置,请找出一个从起始位置到终止位置代价最小的路径: 1.只能沿上下左右四个方向移动 2.总代价是没走一步的 ...
- Codeforces Round #381 (Div. 2)A. Alyona and copybooks(dfs)
A. Alyona and copybooks Problem Description: Little girl Alyona is in a shop to buy some copybooks f ...
- [BZOJ 1082] [SCOI2005] 栅栏 【二分 + DFS验证(有效剪枝)】
题目链接:BZOJ - 1082 题目分析 二分 + DFS验证. 二分到一个 mid ,验证能否选 mid 个根木棍,显然要选最小的 mid 根. 使用 DFS 验证,因为贪心地想一下,要尽量先用提 ...
- UVA - 11882 Biggest Number(dfs+bfs+强剪枝)
题目大意:给出一个方格矩阵,矩阵中有数字0~9,任选一个格子为起点,将走过的数字连起来构成一个数,找出最大的那个数,每个格子只能走一次. 题目分析:DFS.剪枝方案:在当前的处境下,找出所有还能到达的 ...
- HDU 2586 How far away(dfs+邻接表)
How far away [题目链接]How far away [题目类型]dfs+邻接表 &题意: 题目大意:一个村子里有n个房子,这n个房子用n-1条路连接起来,接下了有m次询问,每次询问 ...
- [LeetCode] 339. Nested List Weight Sum_Easy tag:DFS
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- [LeetCode] 559. Maximum Depth of N-ary Tree_Easy tag: DFS
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...
- [LeetCode] 329. Longest Increasing Path in a Matrix_Hard tag: Dynamic Programming, DFS, Memoization
Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...
- poj3279(dfs+二进制枚举思路)
题意转载自https://www.cnblogs.com/blumia/p/poj3279.html 题目属性:DFS 相关题目:poj3276 题目原文:[desc]Farmer John know ...
随机推荐
- C# 最小化到托盘,托盘右击菜单显示
添加notifyIcon控件,并添加Icon,否则托盘没有图标(托盘右键菜单也可直接在属性里添加): 主要的代码: public partial class Form1 : Form { #regio ...
- 超炫酷的jQuery/HTML5应用效果及源码
jQuery非常强大,我们之前也用jQuery分享过很多实用的插件.HTML5可以让网页变得更加绚丽多彩,将HTML5和jQuery结合使用那将发挥更棒的效果. 今天向大家收集了一些关于HTML5和j ...
- WiFidog 广告路由可修改功能更加智能化的几点看法
海蜘蛛Tomato出了mini版,这个对很多做WiFi营销的朋友来说,是一个福音,因为可以直接从FIR302B,一台30多块钱的路由直接刷成Hi-WiFi,而且界面这么漂亮 相信很多人已经对此界面OE ...
- .net framework 4.0 在 VS2010 安装目录下位置 dotNetFx40_Full_x86_x64.exe在磁盘哪个目录?
.net framework 4.0 在 VS2010 安装目录下位置 dotNetFx40_Full_x86_x64.exe在磁盘哪个目录? 使用VS2010开发应用程序完毕后,在发布应用程序时,常 ...
- hbase深入了解
http://blog.csdn.net/u010967382/article/details/37878701?utm_source=tuicool&utm_medium=referral ...
- [转] fitnesse中的Map处理
http://blog.csdn.net/doubeizhucele/article/details/42263887 fintesse会把!{}标记的变量视为HashTable对象,展现到页面上的将 ...
- 【ES】简单使用
import sys reload(sys) sys.setdefaultencoding('utf-8') from datetime import datetime from elasticsea ...
- Synycovery 7.18f 一个优秀的同步软件
Serial Key Name: Vdown RG Code: MCKOFA7MNGUQY7954
- 申请LINE 帐号的所有方法
如果你打算用LINE 交朋友或是做行销,你就必须先要拥有一个甚至许多个LINE 帐号.在本篇文章中,将分享给你目前申请LINE 帐号的所有可能方法. 目前LINE 公司允许大家使用以下二种身分申请LI ...
- NHibernate 集合映射深入 (第五篇) <set>,<list>,<map>,<bag>
一.集合外键 在NHibernate中,典型的用于映射集合类的元素有<set>,<list>,<map>,<bag>,<array>,< ...