코딩테스트 문제 풀이/[백준] 백트래킹(7)
-
C# 14889번 스타트와 링크
using System; using System.Text; namespace beakjoon { class _8 { static int range, length; static int[] tempArr = new int[21]; // 값 출력을 위한 정수 배열 static int[] arr = new int[21]; // 값 출력을 위한 정수 배열 static string[] awaytemp = new string[21]; // 값 출력을 위한 정수 배열 static int[] awayArr = new int[21]; // 중복 제거를 위한 bool 배열 static bool[] visited = new bool[21]; // 2차원 배열 static int[,] all = new int[21, 21]; ..
2022.01.17 -
C# 14888번 연산자 끼워넣기
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _7 { internal class Program { //첫째줄 입력 받는 배열 static int N; //둘째 줄 입력 받는 배열 static string An; //셋째 줄 입력 받는 배열 static string operators; //계산할 값 저장 배열 static string[] AnArray = new string[N]; //int형으로 형 변환한 계산할 값 저장 배열 static int[] AnArray2 = new int[N]; //연산자 배열 static stri..
2022.01.17 -
C# 9663번 N-Queen
using System; using System.Text; namespace beakjoon { class _5 { static int N; // 값 출력을 위한 정수 배열 static int count; // 세로영역 즉, 같은 줄에는 둘 수 없게 하기 위한 배열 static bool[] isY = new bool[14]; //우상향 대각선에 둘 수 없게 하기 위한 배열 static bool[] isDiagonal1 = new bool[27]; //우하향 대각선에 둘 수 없게 하기 위한 배열 //배열이 많은 이유는 4x4체스판에서 (0,3)에 퀸을 두게 되면 x-y가 -3 이므로 음수를 둘 수 없기 때문에 +3을 해줘야함 이 값이 (n-1)임 static bool[] isDiagonal2 = new b..
2022.01.17 -
C# 15652번 N과 M(4)
using System; using System.Text; namespace beakjoon { class _4 { static int range, length; // 값 출력을 위한 정수 배열 static int[] arr = new int[9]; // 배열이 오름차순인지 확인하기 위한 배열 //DFS 알고리즘 public static void DFS(int cnt) { // 출력할 배열이 완성되면 문자열 출력 if (cnt == length) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { sb.Append($"{arr[i]} "); } Console.WriteLine(sb); } // 문자열 완성이 안됬을 시 ..
2022.01.17 -
C# 15651번 N과 M(3)
using System; using System.Text; namespace beakjoon { class _3 { static int range, length, count; // 값 출력을 위한 정수 배열 static int[] arr = new int[9]; // 중복 제거를 위한 bool 배열 static bool[] visited = new bool[9]; // 중복 제거를 위한 bool 배열 static StringBuilder output = new StringBuilder(); //DFS 알고리즘 public static void DFS(int cnt, int max) { if (count == max) Console.WriteLine(output); if (cnt == length) { S..
2022.01.17 -
C# 15650번 N과 M(2)
using System; using System.Text; namespace beakjoon { class _2 { static int range, length; // 값 출력을 위한 정수 배열 static int[] arr = new int[9]; // 배열이 오름차순인지 확인하기 위한 배열 static int[] arrSort = new int[9]; // 중복 제거를 위한 bool 배열 static bool[] visited = new bool[9]; // 한번이라도 쓴적이 있는지를 확인하기 위한 bool 배열 static bool[] isUsed = new bool[9]; //DFS 알고리즘 public static void DFS(int cnt) { // 출력할 배열이 완성되면 문자열 출력 if..
2022.01.17