[BOJ] n과 m 15665 C++ 풀이

Updated:

문제

n과 m

구현

``` cpp #include #include #include #include using namespace std;

vector v; bool visited[10001]; int tmp[7]; int size; int n,m;

void dfs(int idx, int cnt) { if(cnt == m) { for(int i=0; i<m; i++) cout«v[tmp[i]]«’ ‘; cout«“\n”; return; }

for(int i=0; i<v.size(); i++)
{
    tmp[idx] = i;
    dfs(idx + 1, cnt + 1);
} }

int main(void) { ios::sync_with_stdio(false); cin.tie(0); int num; memset(visited, false, sizeof(visited));

cin>>n>>m;

for(int i=0; i<n; i++)
{
    cin>>num; 
    if(!visited[num])
    {
        visited[num] = true;
        v.push_back(num);
    }
}
sort(v.begin(), v.end());
dfs(0, 0);

return 0; } ``` 

Leave a comment