第十三届JAVAA组决赛——10.火柴棒数字
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{
public static int[] w = {6,2,5,5,4,5,6,3,7,6};
public static String[][] f = new String[10][310];
public static String get(char c, int k) {
String res = "";
for(int i = 0; i < k; i++)
res += c;
return res;
}
public static String Maxs(String a, String b) {
if(a.length() == b.length()) {
for(int i = 0; i < a.length(); i++) {
if(a.charAt(i) > b.charAt(i)) return a;
if(a.charAt(i) < b.charAt(i)) return b;
}
return a;
}else{
if(a.length() > b.length()) return a;
else return b;
}
}
public static void main(String[] args) {
for(int i = 0; i < 10; i++)
for(int j = 0; j < 310; j++) f[i][j] = new String();
for(int i = 1; i < 10; i++) {
for(int j = 1; j < 310; j++) {
f[i][j] = Maxs(f[i][j], f[i-1][j]);
for(int k = 1; j >= k * w[i] && k <= 10; k++) {
f[i][j] = Maxs(f[i][j], get((char)('0' + i), k) + f[i-1][j-k*w[i]]);
}
}
}
System.out.println(f[9][300]);
}
}