using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; Panel[,] map = new Panel[4,4]; for(int i=0; i<4; i++) { int[] inpt = Reader.GetInt(); for(int j=0; j<4; j++) { map[i,j] = new Panel(inpt[j]); } } int ans = this.GetAns(map); Console.WriteLine((ans>=0)?"Yes":"No"); } public int GetAns(Panel[,] target) { int x = 0; int y = 0; for(int i=0; i slid = new List(); if(x > 0 && target[y, x-1].CanSlide) { slid.Add(new int[]{y, x-1});; } if(x < target.GetLength(1) - 1 && target[y, x+1].CanSlide) { slid.Add(new int[]{y, x+1});; } if(y > 0 && target[y-1, x].CanSlide) { slid.Add(new int[]{y-1, x});; } if(y < target.GetLength(0)-1 && target[y+1, x].CanSlide) { slid.Add(new int[]{y+1, x});; } foreach (int[] pos in slid) { int nextX = pos[1]; int nextY = pos[0]; Panel[,] subMap = this.DuplicateMap(target); subMap[y, x].Num = target[nextY, nextX].Num; subMap[y, x].CanSlide = false; subMap[nextY, nextX].Num = 0; int ret = this.GetAns(subMap); if(ret >= 0) { ans = Math.Min(ans, ret + 1); } } if(ans == int.MaxValue) { ans = -1; } return ans; } private bool IsGoal(Panel[,] target) { int idx = 1; for(int i=0; i