题目描述
用n根火柴棍(n≤24),可以拼出多少个形如A+B=C的等式?
等式中的A,B,C是用火柴棍拼出的整数(若该数非零则最高位不能是0) 用火柴拼数字0−9 的拼法如图所示:
输入格式
输入文件matches.in 输入一个正整数n。
输出格式
输出文件matches.out 输出一个整数。
输入输出样例
输入样例#1:
14
输出样例#1:
2 说明: 0+1=1 1+0=1
输入样例#2:
18
输出样例#2:
9 说明: 0+4=4 0+11=11 1+10=11 2+2=4 2+7=9 4+0=4 7+2=9 10+1=11 11+0=11
#include<bits/stdc++.h>
using namespace std;
int nn[10] = {6,2,5,5,4,5,6,3,7,6};
int l[4];
int num[999] = {6};
int n, ans;
void void_chat(int x){
for(int i = 0;i <= 999;i++){
if(n - num[i] >= 0){
l[x] = i;
n -= num[i];
if(x == 3){
if(l[1] + l[2] == l[3]&&n == 0) ans++;
}
else{
void_chat(x + 1);
}
n += num[i];
}
}
}
int main(){
freopen("matches.in", "r", stdin);
freopen("matches.out", "w", stdout);
cin >> n;
n -= 4;
for(int i = 0;i <= 999;i++){
int j = i;
while(j >= 1){
num[i] = num[i] + nn[j % 10];
j /= 10;
}
}
void_chat(1);
cout << ans;
return 0;
}