BOJ 15649:NとM(1)-C++
NとM(1)
コード#コード# #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N, M;
int arr[10];
bool isused[10];
void func(int depth){
if(depth == M){
for(int i=0;i < M;i++)
cout << arr[i] << ' ';
cout << '\n';
return;
}else{
for(int i=1;i<=N;i++)
{
if(!isused[i]){
arr[depth] = i;
isused[i] = true;
func(depth+1);
isused[i] = false;
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
func(0);
return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N, M;
int arr[10];
bool isused[10];
void func(int depth){
if(depth == M){
for(int i=0;i < M;i++)
cout << arr[i] << ' ';
cout << '\n';
return;
}else{
for(int i=1;i<=N;i++)
{
if(!isused[i]){
arr[depth] = i;
isused[i] = true;
func(depth+1);
isused[i] = false;
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
func(0);
return 0;
}
:特定の条件を満たすときに任意の数の操作を実行します.
(状況が変化し、ブロックが発生した場合は最後の成功した部分に戻り、他の状況に戻る->逆追跡)
Reference
この問題について(BOJ 15649:NとM(1)-C++), 我々は、より多くの情報をここで見つけました https://velog.io/@neity16/BOJ-15649-N과-M-1-Cテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol