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. 【C语言】用C语言输出“心形”图案

    在你们的世界里,是不是觉得程序猿一点浪漫都不懂?其实不是的,程序猿的世界也是很浪漫滴! 傻瓜版 int main() { printf("❤"); ; } 高级版 //版本一:单个 ...

  2. MySQL对大小写敏感吗

    见字如面,见标题知内容.你有遇到过因为MYSQL对大小写敏感而被坑的体验吗? 之前看过阿里巴巴Java开发手册,在MySql建表规约里有看到: [强制]表名.字段名必须使用小写字母或数字 , 禁止出现 ...

  3. codeforce D. Shortest Cycle(floyd求最短环)

    题目链接:http://codeforces.com/contest/1206/problem/D 给n个点,如果点a[ i ] &a[ j ] 不为0,则点a[ i ] 和 a[ j ] 直 ...

  4. 【visio】故障树分析图

    率属于 商务 故障树是从一个可能的事故开始,自上而下.一层层的寻找顶事件的直接原因和间接原因事件,直到基本原因事件,并用逻辑图把这些事件之间的逻辑关系表达出来. 主要的应用场景:分析复杂问题原因,一个 ...

  5. Java 动态代理实现

    1.依赖 java.lang.reflect.Proxy - 提供了静态方法去创建动态代理类的实例: Interface InvocationHandler - 一个代理实例调用处理程序实现的接口 2 ...

  6. 概率dp (背包+概率) 背包的多一点

    题意:XX想抢劫银行,当危险率低于P的时候才能行动,现在给出每家银行的金钱mi和危险率pi,求最多能获得多少金钱: 题解:危险率是P,那么安全率就是1-P,那么XX抢劫的所有银行的安全率之积就不能小于 ...

  7. python+matplotlib制作雷达图3例分析和pandas读取csv操作

    1.例一 图1 代码1 #第1步:导出模块 import numpy as np import matplotlib.pyplot as plt from matplotlib import font ...

  8. vue 获得当前无素并做相应处理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. java.lang.OutOfMemoryError: GC overhead limit exceeded异常处理

    今天写程序遇到个之前从没遇到的异常-----java.lang.OutOfMemoryError: GC overhead limit exceeded,下面附上解决方法 异常: 解决方法: 鼠标右击 ...

  10. expect 脚本

    实现远程执行 /home/dataexa/test/proxy.expect touch proxy.expect #!/usr/bin/expect set timeout 30 spawn ssh ...