Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

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.

Input

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

S

Output

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


Sample Input 1

Copy
125

Sample Output 1

Copy
176

There are 4 formulas that can be obtained: 1251+2512+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.


Sample Input 2

Copy
9999999999

Sample Output 2

Copy
12656242944

题解:就是给一个数字字符串,然后在字符串中添加“ + ”把所有情况的  和 加和的结果;

   二进制枚举 "+" 位置,字符串最多10位,总共也就2^9 种情况,然后简单操作一下求加上“+” 后的和即可
 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
char s[];
int pos[];
ll num(int l,int r)
{
ll ans=;
for(int i=l;i<=r;i++){
ans=ans*+s[i]-'';
}
return ans;
}
ll solve(int n)
{
int l=-,r=;
ll ans=;
pos[n]=;
for(int i=;i<=n;i++){
if(pos[i]==) r++;
else{
ans+=num(l+,i);
l=i;
}
}
return ans;
}
int main()
{
while(cin>>s){
int n=strlen(s);
ll ans=;
int R= (<<(n-))- ;
for(int i=;i<=R;i++){
mem(pos);
int tot=,temp=i;
while(temp){
pos[tot++]=temp%;
temp=temp/;
}
ans+=solve(n-);
}
printf("%lld\n",ans);
}
return ;
}

AtCoder Beginner Contest 045 C - たくさんの数式 / Many Formulas的更多相关文章

  1. AtCoder Beginner Contest 045 B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)

    Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement Alice, Bob and Charlie ...

  2. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  3. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  4. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  5. 题解 AtCoder Beginner Contest 168

    小兔的话 欢迎大家在评论区留言哦~ AtCoder Beginner Contest 168 A - ∴ (Therefore) B - ... (Triple Dots) C - : (Colon) ...

  6. AtCoder Beginner Contest 224

    AtCoder Beginner Contest 224 A - Tires 思路分析: 判断最后一个字符即可. 代码如下: #include <bits/stdc++.h> using ...

  7. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  8. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  9. AtCoder Beginner Contest 173 题解

    AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...

随机推荐

  1. mysql报错Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage

    mysql报错Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage 在执行cr ...

  2. chkdsk 命令对Raid盘检测和查错、修复

    C:\Documents and Settings\Administrator>chkdsk /?检查磁盘并显示状态报告. CHKDSK [volume[[path]filename]]] [/ ...

  3. aop 日志统一处理

    AOP是Aspect Oriented Programing的简称,面向切面编程.AOP适合于那些具有横切逻辑的应用:如性能监测,访问控制,事务管理.缓存.对象池管理以及日志记录.AOP将这些分散在各 ...

  4. Java 基础 引用数据类型 和 流程控制

    引用数据类型 与定义基本数据类型变量不同,引用数据类型的变量定义及复制有一个相对固定的步骤和格式: 数据类型 变量名 = new 数据类型(); 如:String st = new String(); ...

  5. word2vec 评测 size_diff

    This is a test for word2vecWed Nov 07 16:47:19 2018dir of model1: ./model/window3_ min_count2_worker ...

  6. 【LeetCode每天一题】Add Two Numbers(两链表相加)

    You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...

  7. GitHub上个最有意思的项目合集(技术清单系列)

    没有1K以上的星星都不好意思推荐给大家!林子大了,啥项目都有,这里给大家搜罗了10个Github上有趣的项目.如果你就着辣椒食用本文,一定会激动的流下泪来...... 1.一行代码没有 | 18k s ...

  8. jenkins windows slave 构建c/c++代码

    关于如何再centos系统上的jenkins master下搭建windows系统的jenkins slave节点,本篇博客中不做介绍,如果有需要的话,请参考我的另外一篇博客,在其中介绍了不同系统的j ...

  9. [LeetCode] 598. Range Addition II_Easy tag: Math

    做个基本思路可以用 brute force, 但时间复杂度较高. 因为起始值都为0, 所以肯定是左上角的重合的最小的长方形就是结果, 所以我们求x, y 的最小值, 最后返回x*y. Code    ...

  10. Linux性能优化gprof使用

    gprof用于分析函数调用耗时,可用之抓出最耗时的函数,以便优化程序. gcc链接时也一定要加-pg参数,以使程序运行结束后生成gmon.out文件,供gprof分析. gprof默认不支持多线程程序 ...