next_permutation은 1,2,3,4,5 있을때 다음 순서의 수열을 나열하는데 5개 모두 나열하게 됩니다.
그런데 예를들어 5개중 3개를 선택하는 순열을 만들떄는 그대로 이용할 수가 없습니다.
전체에서 부분의 순열을 만드는 방법이 있을까요?
5개 중 3개를 선택하는 것은 어렵지 않을 것 같네요. 대략 이런 느낌?
for (int i = 1; i <= 5; ++i) for (int j = i + 1; j <= 5; ++j) for (int k = j + 1; k <= 5; ++k) { vector<int> selected = {i, j, k}; next_permutation(selected.begin(), selected.end()); }
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
3개 선택 후 next_permutation 쓰면 되겠네요.
5개 중 3개를 선택하는 것은 어렵지 않을 것 같네요.
대략 이런 느낌?
for (int i = 1; i <= 5; ++i) for (int j = i + 1; j <= 5; ++j) for (int k = j + 1; k <= 5; ++k) { vector<int> selected = {i, j, k}; next_permutation(selected.begin(), selected.end()); }정확성과 일반화는 알아서...
댓글 달기