z_archive/problem32/main_old.cpp
// Use recursion to find all combinations of the smaller sets
Use recursion to find all combinations of the smaller sets
Use recursion to find all combinations of the smaller sets
int gen_perm(list<int> & next_perm, const list<int> & last_perm)
{
	next_perm = last_perm;
	list<int>::iterator it;
	for (it = next_perm.begin(); it != next_perm.end(); it++)
	{
		if (*it != 1)
			break;
	}
	if (it == next_perm.end())
	{
		return 1;
	}
	else
	{
		switch (*it)
		{
		case 200:
			next_perm.insert(it, 100);
			next_perm.insert(it, 100);
			next_perm.erase(it);
			break;
		case 100:
			next_perm.insert(it, 50);
			next_perm.insert(it, 50);
			next_perm.erase(it);
			break;
		case 50:
			next_perm.insert(it, 10);
			next_perm.insert(it, 20);
			next_perm.insert(it, 20);
			next_perm.erase(it);
			break;
		case 20:
			next_perm.insert(it, 10);
			next_perm.insert(it, 10);
			next_perm.erase(it);
			break;
		case 10:
			next_perm.insert(it, 5);
			next_perm.insert(it, 5);
			next_perm.erase(it);
			break;
		case 5:
			next_perm.insert(it, 1);
			next_perm.insert(it, 2);
			next_perm.insert(it, 2);
			next_perm.erase(it);
			break;
		case 2:
			next_perm.insert(it, 1);
			next_perm.insert(it, 1);
			next_perm.erase(it);
			break;
		default:	
			break;
		}
		return 0;
	}
}
int gen_perm ( list < int > & next_perm , const list < int > & last_perm ) { next_perm = last_perm ; list < int > :: iterator it ; for ( it = next_perm . begin ( ) ; it != next_perm . end ( ) ; it ++ ) { if ( * it != 1 ) break ; } if ( it == next_perm . end ( ) ) { return 1 ; } else { switch ( * it ) { case 200 : next_perm . insert ( it , 100 ) ; next_perm . insert ( it , 100 ) ; next_perm . erase ( it ) ; break ; case 100 : next_perm . insert ( it , 50 ) ; next_perm . insert ( it , 50 ) ; next_perm . erase ( it ) ; break ; case 50 : next_perm . insert ( it , 10 ) ; next_perm . insert ( it , 20 ) ; next_perm . insert ( it , 20 ) ; next_perm . erase ( it ) ; break ; case 20 : next_perm . insert ( it , 10 ) ; next_perm . insert ( it , 10 ) ; next_perm . erase ( it ) ; break ; case 10 : next_perm . insert ( it , 5 ) ; next_perm . insert ( it , 5 ) ; next_perm . erase ( it ) ; break ; case 5 : next_perm . insert ( it , 1 ) ; next_perm . insert ( it , 2 ) ; next_perm . insert ( it , 2 ) ; next_perm . erase ( it ) ; break ; case 2 : next_perm . insert ( it , 1 ) ; next_perm . insert ( it , 1 ) ; next_perm . erase ( it ) ; break ; default : break ; } return 0 ; } }
Use recursion to find all combinations of the smaller sets
Use recursion to find all combinations of the smaller sets
// Find the first non-one entry // Do nothing otherwise.