【NOIP2008】T2 火柴棒等式 题解

【NOIP2008】T2 火柴棒等式 题解火柴棒等式(matches.pas/c/cpp)【问题描述】给你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根火柴棍必须全部用上【输入

大家好,欢迎来到IT知识分享网。【NOIP2008】T2

  1. 火柴棒等式
    (matches.pas/c/cpp)
    【问题描述】
    给你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根火柴棍必须全部用上

【输入】
输入文件matches.in共一行,又一个整数n(n<=24)。
【输出】
输出文件matches.out共一行,表示能拼成的不同等式的数目。

【输入输出样例1】
matches.in matches.out
14 2
【输入输出样例1解释】
2个等式为0+1=1和1+0=1。

【输入输出样例2】
matches.in matches.out
18 9
【输入输出样例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

好像我题解写打标不太好….
那就dfs暴力(没什么鬼区别啊喂
反正这个题也纯属送分,没拿到就去审查格式

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cctype>
#include <algorithm>
#define clr(x) memset(x,0,sizeof(x))
#define LL long long
#ifdef WIN32
#define AUTO "%I64d"
#else
#define AUTO "%lld"
#endif

using namespace std;

int main() {
    freopen("matches.in","r",stdin);
    freopen("matches.out","w",stdout);
    int n; scanf("%d",&n);
         if(n <= 12) printf("0\n");
    else if(n == 13) printf("1\n");
    else if(n == 14) printf("2\n");
    else if(n == 15) printf("8\n");
    else if(n == 16) printf("9\n");
    else if(n == 17) printf("6\n");
    else if(n == 18) printf("9\n");
    else if(n == 19) printf("29\n");
    else if(n == 20) printf("39\n");
    else if(n == 21) printf("38\n");
    else if(n == 22) printf("65\n");
    else if(n == 23) printf("88\n");
    else if(n == 24) printf("128\n");
    return 0;
}

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/21019.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信