UVa 195 - Anagram

Summary
This is a standard Permutations problem, to generate all permutations lexicographically.

Explanation
This is a standard Permutations problem. Since there are $$O(n!)$$ permutations, there really are no optimizations needed.

Gotchas
If you try to use the C++ STL next_permutation algorithm, you will have to write your own custom compare function, even though the standard compare will pass the input on the UVA site.

Input
3 LarRy Big HeAd

Output
aLRry aLRyr aLrRy aLryR aLyRr aLyrR aRLry aRLyr aRrLy aRryL aRyLr aRyrL arLRy arLyR arRLy arRyL aryLR aryRL ayLRr ayLrR ayRLr ayRrL ayrLR ayrRL LaRry LaRyr LarRy LaryR LayRr LayrR LRary LRayr LRray LRrya LRyar LRyra LraRy LrayR LrRay LrRya LryaR LryRa LyaRr LyarR LyRar LyRra LyraR LyrRa RaLry RaLyr RarLy RaryL RayLr RayrL RLary RLayr RLray RLrya RLyar RLyra RraLy RrayL RrLay RrLya RryaL RryLa RyaLr RyarL RyLar RyLra RyraL RyrLa raLRy raLyR raRLy raRyL rayLR rayRL rLaRy rLayR rLRay rLRya rLyaR rLyRa rRaLy rRayL rRLay rRLya rRyaL rRyLa ryaLR ryaRL ryLaR ryLRa ryRaL ryRLa yaLRr yaLrR yaRLr yaRrL yarLR yarRL yLaRr yLarR yLRar yLRra yLraR yLrRa yRaLr yRarL yRLar yRLra yRraL yRrLa yraLR yraRL yrLaR yrLRa yrRaL yrRLa Bgi Big gBi giB iBg igB AdeH AdHe AedH AeHd AHde AHed dAeH dAHe deAH deHA dHAe dHeA eAdH eAHd edAH edHA eHAd eHdA HAde HAed HdAe HdeA HeAd HedA

Solutions

 * Code All the Problems