Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- std::vector < std::vector< int >> vec_vec;
- void somarec( int max, int iter, int pos, std::vector<int> vec )
- {
- if( vec.size() == 0 )
- {
- std::vector <int> novo_vec;
- if( max <= 0 )
- {
- novo_vec.push_back( 0 );
- vec_vec.push_back( novo_vec );
- }
- else
- {
- for( int i = 0; i < max; i++ )
- novo_vec.push_back( 1 );
- vec_vec.push_back( novo_vec );
- somarec( max, max, pos, novo_vec );
- }
- }
- else if( pos < vec.size() )
- for( int i = 2; i <= iter; i++ )
- {
- vec[ pos ] = i;
- int soma_parc = 0;
- for( int j = 0; j <= pos; j++ )
- soma_parc += vec[ j ];
- if( soma_parc <= max )
- {
- soma_parc = max - soma_parc;
- for( int j = 1; j <= soma_parc; j++ )
- vec[ j + pos ] = 1;
- vec.resize( soma_parc + pos + 1 );
- vec_vec.push_back( vec );
- }
- somarec( max, i, pos + 1, vec );
- }
- }
- void debug_vec()
- {
- for( int i = 0; i < vec_vec.size(); i++ )
- for( int j = 0, ult = vec_vec[ i ].size(); j < ult; j++ )
- std::cout << vec_vec[i][ j ] << (j == ult - 1 ? "\x0d\x0a" : "+");
- }
- int main()
- {
- std::vector<int> vec( 0 );
- somarec( 7, 0, 0, vec );
- debug_vec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement