Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
Tags
- 가상 채팅서버
- 백준 1992번 풀이
- 백준
- 백준 1992번
- 객체지향의 사실과 오해
- 스파르타코딩클럽 #spartacodingclub #누구나큰일낼수있어
- 타임리프
- 전문가를 위한 스프링5
- 자바의 정석 기초편
- 1시간 만에 끝내는 직장인 코딩 용어
- 백준 #N과 M(4) #백트래킹
- 스프링 MVC 2편
- SQL
- 전문가를 위한 스프링
- spartacodingclub
- 알고리즘
- 백준 2630번
- C++
- thymeleaf
- 스프링 입문을 위한 자바 객체 지향의 원리와 이해
- 스프링심화반
- 스프링
- 스프링 시큐리티 구조
- 채팅서버 설계
- 팀300
- 누구나큰일낼수있어
- 스파르타코딩클럽
- 김영한님
- 스프링 핵심원리 기본편
- JPA
Archives
- Today
- Total
민우의 코딩노트
백준 15650 - N과 M (2) - C++ 본문
[문제]
[풀이]
백트래킹 문제이다!
[코드]
#include <bits/stdc++.h>
using namespace std;
int n,m; // 4, 2
int arr[10];
int arrcheck[10];
int check2 = -1;
void start(int k)
{
if(k == m)
{
for(int i=0; i<m; i++)
{
cout << arr[i] << " ";
}
cout << "\n";
return;
}
for(int i=1; i<=n; i++)
{
if(!arrcheck[i])
{
arrcheck[i] = 1;
if(k > 0) check2 = arr[k-1];
else check2 = -1;
arr[k] = i;
if(check2 < arr[k])
start(k+1);
arrcheck[i] = 0;
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
start(0);
}
'Algorithm > BOJ' 카테고리의 다른 글
백준 15652번 - N과 M (4) / C++ (0) | 2022.01.15 |
---|---|
백준 15651번 - N과 M (3) - C++ (0) | 2022.01.13 |
백준 9663번 N-Queen / C++ (0) | 2022.01.09 |
백준 1182번 부분수열의 합 - C++ (0) | 2022.01.09 |
백준 15649번 - N과 M(1) - C++ (0) | 2022.01.08 |