題目描述
給你n根火柴棍,你可以拼出多少個形如“A+B=C”的等式?等式中的A、B、C是用火柴棍拼出的整數(若該數非零,則最高位不能是000)。用火柴棍拼數字0−9的拼法如圖所示: 注意:加號與等號各自需要兩根火柴棍如果A≠B,則A+B=C與B+A=C視爲不同的等式(A,B,C>=0)n根火柴棍必須全部用上輸入輸出格式輸入格式:
一個整數n(n<=24))。
輸出格式:
一個整數,能拼成的不同等式的數目。
輸入輸出樣例
輸入樣例#1: 14
輸出樣例#1: 2
輸入樣例#2: 18
輸出樣例#2: 9
說明
【輸入輸出樣例1解釋】
2個等式爲:
0+1=1和1+0=1。
【輸入輸出樣例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<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int n, cnt = 0;
int a[2005] = { 6,2,5,5,4,5,6,3,7,6 };
int main()
{
cin >> n;
for (int i = 2000; i > 9; i--)
{
int j = i;
while (j)
{
a[i] += a[j % 10];
j /= 10;
}
}
for (int i = 0; i < 1000; i++)
{
for (int k = 0; k < 1000; k++)
{
if (a[i] + a[k] + a[i + k] + 4 == n)
{
cnt++;
//cout << i << " + " << k << " = " << i + k << endl;
//cout << a[i] << " + " << a[k] << " + " << a[i + k] << "=" << n - 4 << endl;
}
}
}
cout << cnt << endl;
system("pause");
return 0;
}