g***s 发帖数: 3811 | 1 we can preProcess using DP to save time;
time is O(logN×logN)
public class MaxSum {
private static final int MAX_DIGIT = 7;
static int dp[][] = new int[MAX_DIGIT+1][MAX_DIGIT*9+1];
public static int findMax(int x){
int digits = ("" + x).length();
int max = 0;
int t;
for (int sum = 0 ; sum <= 9*digits ; sum++){
max = Math.max(max, t = totalWaysUpto(x, sum));
}
return max;
}
private static int totalWaysUpt... 阅读全帖 |
|