タグ

ブックマーク / www.programming-magic.com (1)

  • 全ての組み合わせを作る【C++】 - Programming Magic

    C++で全ての順列を作りたければ、STLにnext_permutation関数があり、以下のように簡単に作ることができる。 #include <iostream> #include <vector> #include <algorithm> int main(){ const int n = 3; std::vector<int> data; // [0, 1, 2, ....]というサイズnの配列を作成 for(int i=0; i<n; ++i){ data.push_back(i); } // 全ての順列を出力 do{ std::cout << "[ " << data[0]; for(unsigned int i=1; i<data.size(); ++i){ std::cout << ", " << data[i]; } std::cout << " ]" << std::end

    h6n
    h6n 2011/04/06
    next_permutation
  • 1