打表法:在数据量不大的情况下,提前将所有可能的结果全部列出来。然后,根据要求,直接从结果集中获取结果
import java.util.Scanner;
public class P1149 {
static int n;
static int[] a = {6,2,5,5,4,5,6,3,7,6};
static int[] b = new int[25];
public static void main(String[] args) {
// 打表程序,将结果给b数组
// daBiao();
// System.out.println(Arrays.toString(b));
b= new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,8,9,6,9,29,39,38,65,88,128};
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
System.out.println(b[n]);
}
private static void daBiao() {
for(int i=0;i<=24;i++) {
int sum=0;
for(int j=0;j<10000;j++) {
for(int k=0;k<10000;k++) {
int temp=j+k;
if(getMatch(j)+getMatch(k)+getMatch(temp)==(i-4)) {
sum++;
}
}
}
b[i] = sum;
}
}
private static int getMatch(int num) {
int hcgCount=0;
if(num==0) {
return a[num];
}
while(num>0) {
int t = num%10;
hcgCount += a[t];
num /= 10;
}
return hcgCount;
}
}