題名なし
よくあるnext_permutationのサンプル
#include<iostream> #include<vector> #include<algorithm> void printvec( std::vector<int> &v){ for( int i = 0; i < v.size(); ++i ){ std::cout << v[i] << " "; } std::cout << std::endl; } int main(){ std::vector<int> v, e; v.push_back(1); v.push_back(2); v.push_back(3); printvec( v ); while( std::next_permutation( v.begin(), v.end() ) ) printvec( v ); return 0;
出力
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
ループを変えてみる
for( int i= 0; i < 12; ++i ){ std::cout << std::next_permutation( v.begin(), v.end() ) << " "; printvec( v ); }
出力
1 2 3 1 1 3 2 1 2 1 3 1 2 3 1 1 3 1 2 1 3 2 1 0 1 2 3 1 1 3 2 1 2 1 3 1 2 3 1 1 3 1 2 1 3 2 1 0 1 2 3
おお、覚えていらっしゃるのか。