티스토리 뷰
백준 소스코드 [C++] 1799 비숍
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
typedef long long ll;
using namespace std;
int n;
int arr[12][12];
bool visited[12][12];
vector <pii> color[2];
int res[2];
bool chk(int y, int x) {
int Y = y, X = x;
while (1 <= Y && 1 <= X) if (visited[Y--][X--] == true) return false;
Y = y, X = x;
while (1 <= Y && X <= n) if (visited[Y--][X++] == true) return false;
return true;
}
void dfs(int cnt, vector<pii> &v,int k,int sum) {
for(int i=cnt;i<v.size();i++)
if (chk(v[i].first,v[i].second) == true) {
visited[v[i].first][v[i].second] = true;
res[k] = max(res[k], sum+1);
dfs(i + 1, v, k,sum+1);
visited[v[i].first][v[i].second] = false;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1;i <= n;i++)for (int j = 1;j <= n;j++) {
cin >> arr[i][j];
if (arr[i][j] == 1) color[(i + j) % 2].push_back({ i, j });
}
dfs(0, color[0],0,0);
dfs(0, color[1],1,0);
cout << res[0] + res[1];
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 11438 LCA 2 (0) | 2021.02.24 |
---|---|
백준 소스코드 [C++] 11437 LCA (0) | 2021.02.24 |
백준 소스코드 [C++] 2283 구간 자르기 (0) | 2021.02.22 |
백준 소스코드 [C++] 1644 소수의 연속합 (0) | 2021.02.22 |
백준 소스코드 [C++] 11728 배열 합치기 (0) | 2021.02.21 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- State Restoration
- 포드 풀커슨 알고리즘
- HIG
- WWDC17
- 최단경로문제
- 네트워크 유량
- 최단경로 문제
- 벨만포드 알고리즘
- IOS
- 부스트캠프 6기
- 최단경로 알고리즘
- 최대 매칭
- 강한 순환 참조
- WWDC19
- test coverage
- CompositionalLayout
- MeTal
- WWDC21
- 컴퓨터 추상화
- 다익스트라 시간복잡도
- observeOn
- 코딩대회
- CPU와 Memory
- mach-o
- 벨만포드 시간복잡도
- Testable
- rxswift
- 에드몬드 카프 알고리즘
- 네트워크 플로우
- WWDC16
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함