From 28aa41dc61138b648ecf03b49d413d3bf0de0655 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EA=B9=80=EC=8B=9C=ED=99=98?= <ksshhses@ajou.ac.kr>
Date: Thu, 12 May 2022 12:12:39 +0900
Subject: [PATCH] 22.05.12

---
 Backtracking/3980.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++
 Backtracking/6443.cpp | 40 ++++++++++++++++++++++++++++++++++
 Backtracking/9663.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
 create mode 100644 Backtracking/3980.cpp
 create mode 100644 Backtracking/6443.cpp
 create mode 100644 Backtracking/9663.cpp

diff --git a/Backtracking/3980.cpp b/Backtracking/3980.cpp
new file mode 100644
index 0000000..6595204
--- /dev/null
+++ b/Backtracking/3980.cpp
@@ -0,0 +1,49 @@
+#include<iostream>
+#include<vector>
+#include<algorithm>
+using namespace std;
+
+int ans;
+int check[11];
+int player[11][11];
+
+void back(int play, int sum)
+{
+    if(play == 11)
+    {
+        ans = max(ans, sum);
+        return;
+    }
+
+    for(int i=0;i<11;i++)
+    {
+        if(player[play][i] != 0 && check[i] == 0)
+        {
+            check[i] = 1;
+            back(play+1, sum + player[play][i]);
+            check[i] = 0;
+        }
+    }
+}
+
+int main()
+{
+    ios_base::sync_with_stdio(false);
+    cin.tie(NULL);
+    cout.tie(NULL);
+
+    int T;
+    cin >> T;
+    while(T--)
+    {
+        ans = 0;
+        
+        for(int i=0;i<11;i++)
+            for(int j=0;j<11;j++)
+                cin >> player[i][j];
+
+        back(0, 0);
+
+        cout << ans << "\n";
+    }
+}
\ No newline at end of file
diff --git a/Backtracking/6443.cpp b/Backtracking/6443.cpp
new file mode 100644
index 0000000..72e3f83
--- /dev/null
+++ b/Backtracking/6443.cpp
@@ -0,0 +1,40 @@
+#include<iostream>
+#include<vector>
+#include<string>
+#include<algorithm>
+using namespace std;
+
+void back(int idx, string str, int len)
+{
+    if(idx == len - 1)
+    {
+        cout << str << "\n";
+        return;
+    }
+
+    for(int i=idx;i<len;i++)
+    {
+        if(i != idx && str[i] == str[idx])
+            continue;
+        if(str[i] != str[idx])
+            swap(str[i], str[idx]);
+
+        back(idx+1, str, len);
+    }
+
+}
+
+int main()
+{
+    int t;
+    cin >> t;
+    while(t--)
+    {
+        string in;
+        cin >> in;
+
+        sort(in.begin(), in.end());
+
+        back(0, in, in.size());
+    }
+}
\ No newline at end of file
diff --git a/Backtracking/9663.cpp b/Backtracking/9663.cpp
new file mode 100644
index 0000000..1321066
--- /dev/null
+++ b/Backtracking/9663.cpp
@@ -0,0 +1,50 @@
+#include<iostream>
+#include<vector>
+using namespace std;
+
+int N, ans;
+int board[16][16];
+
+bool check(int x, int y)
+{
+    for(int i = 0; i<N;i++)
+        if(board[x][i] == 1 || board[i][y] == 1)
+            return false;
+
+    for(int i=x, j=y;i>=0 && j>=0;i--,j--)
+        if(board[i][j] == 1)
+            return false;
+    
+    for(int i=x, j=y;i>=0 && j<N;i--,j++)
+        if(board[i][j] == 1)
+            return false;
+    
+    return true;
+}
+
+void back(int idx)
+{
+    if(idx == N)
+    {
+        ans++;
+        return;
+    }
+
+    for(int i=0;i<N;i++)
+        if(check(idx,i) == true)
+        {
+            board[idx][i] = 1;
+            back(idx + 1);
+            board[idx][i] = 0;
+        }
+}
+
+int main()
+{
+    cin >> N;
+
+    back(0);
+
+    cout << ans;
+
+}
\ No newline at end of file
-- 
GitLab