Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
竟然1A了,代码……#include <iostream> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <string> #include <cstdio> #include <climits> #include <queue> using namespace std; int l, r; int rn[8]; int value[8]; int final[8]; int rk = 0; int maxn = 0; int maxnn = 0; void dfs(int k, int in) { if (k > l) return; if (in == rk) { if (maxn < k) { maxnn = 0; maxn = k; memcpy(final, value, sizeof(final)); } else if(maxn == k) { maxnn++; } } for (int i=in; i < rk; i++) { for (int j=1; j <= value[i-1] * 10; j+=value[i-1] * 10-1) { value[i] = j; dfs(k+rn[i]*j, i+1); value[i] = 0; } } } int main() { while (scanf("%d%d", &l, &r), l||r) { int suml = 0; int t = r; rk = 0; while (t > 0) { rn[rk++] = t%10; suml += rn[rk-1]; t /= 10; } if (suml > l) { printf("error\n"); continue; } maxn = 0; value[0] = 1; dfs(rn[0], 1); if (maxnn > 0) printf("rejected\n"); else { printf("%d ", maxn); for (int i=rk-1; i >=0; i--) { printf("%d", rn[i]); if (final[i] == 1) printf(" "); } printf("\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator