P1149 火柴棒等式

https://www.luogu.org/problem/P1149

 

#include <iostream>
#include <string>
#include <string.h>
#include <stdio.h>

using namespace std;
char array[10]={6,2,5,5,4,5,6,3,7,6};
int dst[24] = {0};

char str[8]={0};

int calc(int n)
{
    memset(str, 0, 8);
    sprintf(str, "%d", n);
    int len=strlen(str);
    int iRet = 0;
    for (int i = 0; i < len; i++)
    {
        iRet += array[str[i]-'0'];
    }
    return iRet;
}

int main(void)
{
    for(int i=0;i <= 999; i++)
    {
        int i1 = calc(i);
        if (i1>16)
        {
            continue;
        }
        for(int j=0;j<=999;j++)
        {
            int j1 = calc(j);
            if (j1>16 || i1+j1 > 18)
            {
                continue;
            }
            int k=i+j;
            int k1=calc(k);
            int iUse=i1+j1+k1;
            if (iUse <= 20)
            {
                dst[iUse]++;
            }
        }
    }
    int n;
    cin>>n;

    if(n<13)
    {
        cout <<0<<endl;
    }
    else
    {
        n-=4;
        cout <<dst[n]<<endl;
    }
    return 0;
}
 

 

简化版本

#include <iostream>
using namespace std;
int dst[25] = {0};

int main(void)
{
    dst[13] = 1;
    dst[14] = 2;
    dst[15] = 8;
    dst[16] = 9;
    dst[17] = 6;
    dst[18] = 9;
    dst[19] = 29;
    dst[20] = 39;
    dst[21] = 38;
    dst[22] = 65;
    dst[23] = 88;
    dst[24] = 128;
    int n;
    cin>>n;
    cout << dst[n] << endl;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值