标签:down because contains mat mit dig use for bottom
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13669 Accepted Submission(s): 7150
#include <iostream> #include <cstdlib> #include <algorithm> #include <cstdio> using namespace std; int len, tar, res[6]; char s[13]; bool vis[13],flag; bool cmp(char a, char b) { return a > b; } int pow(int n, int times) { int res = n; times--; while (times--) { res *= n; } return res; } void dfs(int n) { if (n == 5) { int sum = res[0] - pow(res[1], 2) + pow(res[2], 3) - pow(res[3], 4) + pow(res[4], 5); if (sum == tar) flag = true; return; } for (int i = 0; i < len; i++) { if (!vis[i] && !flag) { res[n] = s[i] - ‘A‘ + 1; vis[i] = true; dfs(n + 1); vis[i] = false; } } return; } int main(void) { ios::sync_with_stdio(false); cin.tie(false); while (cin >> tar >> s) { if (tar == 0 && strcmp(s, "END") == 0) break; flag = false; len = strlen(s); memset(vis, false, sizeof(vis)); sort(s, s + len, cmp); dfs(0); if (flag) { for (int i = 0; i < 5; i++) printf("%c", res[i] + ‘A‘ - 1); cout << endl; } else cout << "no solution" << ‘\n‘; } return 0; }
标签:down because contains mat mit dig use for bottom
原文地址:http://www.cnblogs.com/ray-coding-in-rays/p/6407140.html