Language: C++

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>

#define MAX 11
#define S_MAX 101

using namespace std;

bool InsideCommon( const char *a, const char *b ){
	if( strstr( a, b ) )
		return true;
	else
		return false;
}

void Overlap( const char *a, const char *b, char * ret ){
	unsigned int len = 0;
	unsigned int alen = strlen(a);
	unsigned int blen = strlen(b);
	unsigned int min_len = min( alen, blen );
	
	for(unsigned int i = min_len; i >= 1; --i){
		bool bOk = true;
		for(unsigned int j = 0; j < i; ++j){
			if( a[ alen - i + j ] != b[ j ] ){
				bOk = false;
			}
		}
		if( bOk ){
			len = i;
			break;
		}
	}
	strcpy( ret, a );
	strcat( ret, b + len );
}

int invest;

void solve(int n, const char strs[MAX-1][MAX], bool *bUsed, char *now, char *ans){
	bool bAllUsed = true;


	//printf("NOW: %s\n", now);

	for(int i = 0; i < n; ++i){
		if( !bUsed[i] ){
			char t[S_MAX]="";
			bAllUsed = false;
			
			strcpy(t,now);
			if( InsideCommon( t, strs[i] ) ){
				bUsed[i] = true;
				solve( n, strs, bUsed, t, ans );
				bUsed[i] = false;
				continue;
			}
			if( InsideCommon( strs[i], t ) ){
				strcpy( t, strs[i] );
				bUsed[i] = true;
				solve( n, strs, bUsed, t, ans );
				bUsed[i] = false;
				continue;
			}

			Overlap( now, strs[i], t );
			bUsed[i] = true;
			solve( n, strs, bUsed, t, ans );
			bUsed[i] = false;
		}
	}
	
	if( bAllUsed ){
		if( strlen( now ) < strlen( ans ) )
			strcpy( ans, now );
		else if( strlen( now ) == strlen( ans ) && strcmp( now, ans ) <= 0 )
			strcpy( ans, now );

		return ;
	}
}

int main(){
	while(true){
		int n;
		char now[S_MAX]="";
		char ans[S_MAX]="";
		char strs[MAX-1][MAX]={{"",},};
		bool bUsed[MAX-1]={false,};

		scanf("%d", &n);
		if(n == 0)break;

		/* input */
		for(int i = 0; i < n; ++i){
			scanf("%s", strs[i]);
			bool bSkip = false;
			
			for(int j = 0; j < i; ++j){
				if( InsideCommon( strs[j], strs[i] ) ){
					bSkip = true;
					break;
				}
			}
			
			if( bSkip ){
				--n;
				--i;
				continue;
			}
			strcat(ans,strs[i]);
		}

		invest = 0;
		//printf("N: %d BEST STATE: %s\n", n, ans);
		solve( n, strs, bUsed, now, ans );
		
		printf("%s\n", ans);
	}
}

Compiler output:
a.cc: In function 'bool InsideCommon(const char*, const char*)':
a.cc:13:13: error: 'strstr' was not declared in this scope
   13 |         if( strstr( a, b ) )
      |             ^~~~~~
a.cc:6:1: note: 'strstr' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include<queue>
  +++ |+#include <cstring>
    6 | 
a.cc: In function 'void Overlap(const char*, const char*, char*)':
a.cc:21:29: error: 'strlen' was not declared in this scope
   21 |         unsigned int alen = strlen(a);
      |                             ^~~~~~
a.cc:21:29: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:37:9: error: 'strcpy' was not declared in this scope
   37 |         strcpy( ret, a );
      |         ^~~~~~
a.cc:37:9: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:38:9: error: 'strcat' was not declared in this scope
   38 |         strcat( ret, b + len );
      |         ^~~~~~
a.cc:38:9: note: 'strcat' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc: In function 'void solve(int, const char (*)[11], bool*, char*, char*)':
a.cc:54:25: error: 'strcpy' was not declared in this scope
   54 |                         strcpy(t,now);
      |                         ^~~~~~
a.cc:54:25: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:77:21: error: 'strlen' was not declared in this scope
   77 |                 if( strlen( now ) < strlen( ans ) )
      |                     ^~~~~~
a.cc:77:21: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:78:25: error: 'strcpy' was not declared in this scope
   78 |                         strcpy( ans, now );
      |                         ^~~~~~
a.cc:78:25: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:79:60: error: 'strcmp' was not declared in this scope
   79 |                 else if( strlen( now ) == strlen( ans ) && strcmp( now, ans ) <= 0 )
      |                                                            ^~~~~~
a.cc:79:60: note: 'strcmp' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:80:25: error: 'strcpy' was not declared in this scope
   80 |                         strcpy( ans, now );
      |                         ^~~~~~
a.cc:80:25: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc: In function 'int main()':
a.cc:114:25: error: 'strcat' was not declared in this scope
  114 |                         strcat(ans,strs[i]);
      |                         ^~~~~~
a.cc:114:25: note: 'strcat' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc: In function 'bool InsideCommon(const char*, const char*)':
a.cc:17:1: warning: control reaches end of non-void function [-Wreturn-type]
   17 | }
      | ^