您的位置:首页 > 其它

zcmu-1967

2017-08-24 15:13 99 查看

1967: 火柴棒等式

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 15  Solved: 11

[Submit][Status][Web
Board]

Description

给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A、B、C是用火柴棍拼出的整数(若该数非零,则最高位不能是0)。用火柴棍拼数字0-9的拼法如图所示:



注意:

1. 加号与等号各自需要两根火柴棍

2. 如果A≠B,则A+B=C与B+A=C视为不同的等式(A、B、C>=0)

3. n根火柴棍必须全部用上

Input

输入文件matches.in共一行,又一个整数n(n<=24)。

Output

输出文件matches.out共一行,表示能拼成的不同等式的数目。

Sample Input

1418

Sample Output

29

HINT

【输入输出样例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

Source

NOIP2008提高组

思路:预处理+枚举,心痛的一题,哎。可以算得24根火柴可以最大的组成1110+1=1111,所以可以假设最大的数为1111

代码:

#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int m[2010];
int a[10]={6,2,5,5,4,5,6,3,7,6};
memset(m,0,sizeof(m));
for(int i=0; i<=1999; i++)
{
if(i==0)m[i]=a[i];
else
{
int x=i;
while(x)
{
int xx=x%10;
m[i]+=a[xx];
x/=10;
}
}
}
int n;
while(~scanf("%d",&n))
{
int ans=0;
for(int i=0; i<=1111; i++)
for(int j=0; j<=1111; j++)
{
if(m[i]+m[j]+m[i+j]+4==n)ans++;
}
printf("%d\n",ans);
}
return 0;
}


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: