题目链接:http://acm.hrbust.edu.cn/contests/index.php?act=showproblem&cid=1570&p=F
解题思路:简单的dfs
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 int n; 5 char s[10][6],mp[10][6]; 6 void dfs(int x,string ans) 7 { 8 if(x==n+1){ 9 cout<<ans<<endl; 10 return; 11 } 12 for(int i=0; i<strlen(mp[x]); i++){ 13 dfs(x+1,ans+mp[x][i]); 14 } 15 } 16 int main() 17 { 18 while(~scanf("%s",s[1])){ 19 for(int i=2; i<=9; i++) 20 scanf("%s",s[i]); 21 scanf("%d",&n); 22 for(int i=1; i<=n; i++){ 23 int k; 24 scanf("%d",&k); 25 strcpy(mp[i],s[k]); 26 } 27 dfs(1,""); 28 } 29 return 0; 30 }
原文:https://www.cnblogs.com/wxyblogs/p/12904731.html