MakerHyeon

순열,조합 (python,c++) 본문

Algorithm/AlgoStudy

순열,조합 (python,c++)

유쾌한고등어 2023. 2. 12. 14:18

◆ 순열

 

1) python

from itertools import permutations

v = [0,1,2,3]

for i in permutations(v,4):
    print(i)

2) C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    vector<int> v{0, 1, 2, 3};
    do
    {
        for (int i : v)
            printf(" %d", i);
        printf("\n");
    } while (next_permutation(v.begin(), v.end()));
}

◆ 조합

 

1) python

from itertools import combinations

v=[0,1,2,3]

for i in combinations(v,2):
    print(i)

 

Comments