5 a?bb? 3 aaa
aabba QwQ
#include <cstdio> #include <cstring> char s[1005]; int n; bool flag; bool ok() { for(int i = 0; i < n / 2; i++) if(s[i] != s[n - i - 1]) return true; return false; } void DFS(int pos) { if(pos == n) { if(ok()) flag = true; return; } if(s[pos] != '?') { DFS(pos + 1); if(flag) return; } else { for(char j = 'a'; j <= 'z'; j++) { s[pos] = j; DFS(pos + 1); if(flag) return; s[pos] = '?'; } } return; } int main() { while(scanf("%d", &n) != EOF) { flag = false; scanf("%s", s); DFS(0); if(flag) printf("%s\n", s); else printf("QwQ\n"); } }
HDU 5202 Rikka with string (水DFS)
原文地址:http://blog.csdn.net/tc_to_top/article/details/45059853