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.

样例输入 Copy

125

样例输出 Copy

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 <bits/stdc++.h>
using namespace std;
string s;
int cnt;
long long sum,t;
int main() {
//freopen("in", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s;
cnt = s.size();
for(int i = 0; i < (1 << (cnt - 1));i++){
t = s[0] - '0';
for(int j = 0; j < cnt; j++){
if(i & (1 << j) || j == cnt - 1){
sum += t;
t = 0;
if(j == cnt - 1) break;
} t = t * 10 + (s[j + 1] - '0'); }
}
cout << sum << endl;
return 0;
}

大佬的博客

Many Formulas的更多相关文章

  1. たくさんの数式 / Many Formulas AtCoder - 2067 (枚举二进制)

    Problem Statement You are given a string S consisting of digits between 1 and 9, inclusive. You can ...

  2. AtCoder Beginner Contest 045 C - たくさんの数式 / Many Formulas

    Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement You are given a string ...

  3. Codeforces 424 C. Magic Formulas

    xor是满足交换律的,展开后发现仅仅要能高速求出 [1mod1....1modn],....,[nmod1...nmodn]的矩阵的xor即可了....然后找个规律 C. Magic Formulas ...

  4. CodeForce 424C Magic Formulas

    这个题就是求出给的公式的结果. 仅仅要知道异或运算满足交换律跟结合律即可了.之后就是化简公式. #include<map> #include<string> #include& ...

  5. codeforce-424C. Magic Formulas(数学)

    C. Magic Formulas time limit per test:2 seconds     memory limit per test:256 megabytes   input stan ...

  6. Experimental Educational Round: VolBIT Formulas Blitz

    cf的一次数学场... 递推 C 题意:长度<=n的数只含有7或8的个数 分析:每一位都有2种可能,累加不同长度的方案数就是总方案数 组合 G 题意:将5个苹果和3个梨放进n个不同的盒子里的方案 ...

  7. Codeforces Round #242 (Div. 2) C. Magic Formulas

    解题思路是: Q=q1^q2.......^qn = p1^p2......^pn^((1%1)^....(1%n))^((2%1)^......(2%n))^.... 故Q的求解过程分成两部分 第一 ...

  8. Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)

    题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1.  交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ ...

  9. Npoi 导出Excel 下拉列表异常: String literals in formulas can't be bigger than 255 Chars ASCII

    代码: public static void dropDownList(string[] datas, string filePath) { HSSFWorkbook workbook = new H ...

随机推荐

  1. centos7 sshpass 用法详解

    可以参考文章:https://www.cnblogs.com/kaishirenshi/p/7921308.html 安装方式直接通过yum 安装 yum -y install sshpass 常用的 ...

  2. selenium选择框

    自动化测试中,会遇到选择框,针对该类元素,selenium提供类Select类来处理,使用select类先导入:from selenium.webdriver.support.select impor ...

  3. jQuery对象和语法

    jQuery类型 引入jquery.js时,其实是向全局作用域中,添加了一个新的类型--jQuery. 构造函数:负责创建jQuery类型的对象. 原型对象:保存jQuery对象可用的所有简化版API ...

  4. Python记:列表和元组之序列相加

    _______________坐而论道,不如起而行之! 序列乘法运算示例:

  5. hadoop学习笔记(十):hdfs在命令行的基本操作命令(包括文件的上传和下载和hdfs中的文件的查看等)

    hdfs命令行 ()查看帮助 hdfs dfs -help ()查看当前目录信息 hdfs dfs -ls / ()上传文件 hdfs dfs -put /本地路径 /hdfs路径 ()剪切文件 hd ...

  6. hdu1874 (spfa 最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1874 很简单的最短路问题,刚刚学习spfa,其实很简单,思想和一维动态规划差不多,数组d[i]表示起点 ...

  7. 用Python开发实用程序 – 计算器

    一段时间前,自己制作了一个库 “sui-math”.这其实是math的翻版.做完后,python既然可以轻易的完成任何的数学计算,何不用python开发一个小程序专门用以计算呢? 现在我们越来越依赖于 ...

  8. office2013激活工具,可以激活新版本office 2013

    耽误一上午没激活成功,最后还是找到了激活文件KMSpico v9.0.6.zip 链接:https://pan.baidu.com/s/1WEyJm8kVnqDONRJRHTRQiQ 提取码:4h45 ...

  9. supervisor的使用点滴

    supervisor的安装 pip install supervisor 安装成功后步骤 1.创建配置文件 echo_supervisord_conf  > /etc/supervisord.c ...

  10. Go第三方库之tail

    Tail Demo // tail.TailFile()函数开启goroutine去读取文件,通过channel格式的t.lines传递内容. t, err := tail.TailFile(&quo ...