6467: Many Formulas(二进制暴力)

6467: Many Formulas

时间限制: 1 Sec   内存限制: 128 MB
提交: 145   解决: 80
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

You are given a string S consisting of digits between 1 and 9, inclusive. You can insert the letter + into some of the positions (possibly none) between two letters in this string. Here, + must not occur consecutively after insertion.
All strings that can be obtained in this way can be evaluated as formulas.
Evaluate all possible formulas, and print the sum of the results.

Constraints
1≤|S|≤10
All letters in S are digits between 1 and 9, inclusive.

输入

The input is given from Standard Input in the following format:
S

输出

Print the sum of the evaluated value over all possible formulas.

样例输入

125

样例输出

176

提示

There are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,

125
1+25=26
12+5=17
1+2+5=8
Thus, the sum is 125+26+17+8=176.


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FAST_IO ios::sync_with_stdio(false)
#define mem(a,b) memset(a,b,sizeof(a))
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const long long INF=0x7FFFFFFFFFFFFFFFLL;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
 
 
int main()
{
    char s[105];
    scanf("%s", s);
    int a[1005], len=strlen(s);
    long long x=1, ans=0;
    for(int i=0;i<pow(2, len-1);i++)
    {
        memset(a, 0, sizeof(a));
        long long temp=i, cnt=0;
        while(temp)
        {
            a[cnt++]=temp%2;
            temp/=2;
        }
        long long sum=0;
        temp=s[0]-'0';
        for(int j=0;j<len-1;j++)
        {
            if(a[j])
            {
                sum+=temp;
                temp=s[j+1]-'0';
            }
            else
                temp=temp*10+s[j+1]-'0';
        }
        ans+=sum+temp;
    }
    printf("%lld\n", ans);
    return 0;
}
 
/**************************************************************
    Problem: 6467
    User: ldu_reserver201701
    Language: C++
    Result: 正确
    Time:0 ms
    Memory:1892 kb
****************************************************************/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hhjian6666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值