标签:others span isp contain abc blog mem 题意 position
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3966 Accepted Submission(s): 2028
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; char a[15], b[10]; int visit[15]; int n,num,len; bool judge = false; bool cmp(char a, char b) { return a>b; } void init() { len = strlen(a); judge = false; memset(visit,0,sizeof(visit)); sort(a,a+len,cmp); for(int i = 0;i<len;++i){ a[i] = a[i] -‘A‘ + 1; } } void lnit() { for(int i = 0;i<5;++i) b[i] = b[i]+‘A‘-1; } bool check() { if(n == b[0] - b[1]*b[1] + b[2]*b[2]*b[2] - b[3]*b[3]*b[3]*b[3] + b[4]*b[4]*b[4]*b[4]*b[4]){ judge = true; return true; }else return false; } void dfs(int depth) { //递归边界 if(judge) return; if(depth == 5) {check(); return;} for(int i = 0;i<len;++i){ if(!visit[i]&&!judge){ b[depth] = a[i]; visit[i] = 1; dfs(depth+1); visit[i] = 0; } } } int main() { //freopen("in.txt","r",stdin); while(scanf("%d %s",&n,a)&& !(n==0 && !strcmp(a,"END"))){ init(); dfs(0); lnit(); if(judge)printf("%s\n",b); else printf("no solution\n"); } return 0; }
标签:others span isp contain abc blog mem 题意 position
原文地址:http://www.cnblogs.com/Roni-i/p/7435924.html