标签:style blog class code tar color get int string 2014 404
#include <stdio.h> #include <string.h> const int N = 105; const int M = 3005; const int num[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int n, m; char dp[N][M][55], ans[55], tmp[55]; void init() { scanf("%d", &m); memset(dp, 0, sizeof(dp)); memset(ans, 0, sizeof(ans)); dp[0][0][0] = ‘0‘; } int numcmp(char *a, char *b) { int lena = strlen(a); int lenb = strlen(b); if (lena < lenb) return -1; if (lena > lenb) return 1; return strcmp(a, b); } void DP(char *a, char *b, int k) { memset(tmp, 0, sizeof(tmp)); strcpy(tmp, b); int len = strlen(b); if (tmp[0] == ‘0‘) tmp[0] = ‘0‘ + k; else tmp[len] = ‘0‘ + k; if (numcmp(a, tmp) < 0) strcpy(a, tmp); } int main() { int cas = 0; while (~scanf("%d", &n) && n) { init(); for (int i = 0; i <= n; i++) { for (int j = 0; j < m; j++) { if (strlen(dp[i][j]) == 0) continue; for (int k = 0; k < 10; k++) { if (i + num[k] > n) continue; DP(dp[i + num[k]][(j * 10 + k) % m], dp[i][j], k); } } if (i != 0 && numcmp(ans, dp[i][0]) < 0) strcpy(ans, dp[i][0]); } printf("Case %d: ", ++cas); if (ans[0] == 0) printf("-1\n"); else printf("%s\n", ans); } return 0; }
UVA 12105 - Bigger is Better(DP+高精度),码迷,mamicode.com
UVA 12105 - Bigger is Better(DP+高精度)
标签:style blog class code tar color get int string 2014 404
原文地址:http://blog.csdn.net/accelerator_/article/details/24786415