티스토리 뷰

Algorithm/BOJ

15654 N과 M (5)

henry1214 2018. 6. 6. 16:46

https://www.acmicpc.net/problem/15654



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
31
32
33
34
35
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
 
int n,m,a[8],c[10001];
vector<int> v;
 
void go()
{
    if(v.size()==m)
    {
        for(auto i : v)
            printf("%d ",i);
        printf("\n");
        return;
    }
    for(int i=0;i<n;i++)
    {
        if(c[a[i]]) continue;
        c[a[i]]=1,v.push_back(a[i]);
        go();
        c[a[i]]=0,v.pop_back();
    }
}
 
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    go();
    return 0;
}
cs


'Algorithm > BOJ' 카테고리의 다른 글

10219 Meats On The Grill  (0) 2018.06.07
11502 세 개의 소수 문제  (0) 2018.06.06
15649 N과 M (1)  (0) 2018.06.06
3067 Coins  (0) 2018.05.19
15685 드래곤 커브  (3) 2018.04.16
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday