文章
13
粉丝
386
获赞
2
访问
65.2k
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int matrix[6][6], a, b, c, d, minimum;
bool visited[6][6];
int pos[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void dfs(int x1, int y1, int x2, int y2, int statue, int price){
if(x1 == x2 && y1 == y2) minimum = min(minimum, price);
else{
for(int i = 0; i < 4; i++){
int nx = x1 + pos[i][0];
int ny = y1 + pos[i][1];
if(nx < 0 || nx > 5 || ny < 0 || ny > 5 || visited[nx][ny]) continue;
visited[nx][ny] = true;
int temp = statue * matrix[nx][ny];
dfs(nx, ny, x2, y2, temp % 4 + 1, price + temp);
visited[nx][ny] = false;
}
}
}
int main(){
while(scanf("%d", &matrix[0][0]) != EOF){
memset(visited, false, sizeof(visited));
for(int i = 0; i < 6; i++){
for(int j = 0; j < 6; j++){
...
登录后发布评论
为什么我感觉有点读不懂题