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. dxCameraControl控件(拍照)

    拍照演示 主要属性设置 Active:True DeviceIndex:设备号,默认为0 其他方法 procedure Capture; //捕获 procedure Pause; //暂停 proc ...

  2. 004-Quartz存储与持久化-基于quartz.properties的配置

    一.概述 Quartz提供两种基本作业存储类型.第一种类型叫做RAMJobStore,第二种类型叫做JDBC作业存储.在默认情况下Quartz将任务调度的运行信息保存在内存中,这种方法提供了最佳的性能 ...

  3. 003-hive安装

    http://www.aboutyun.com/thread-6902-1-1.html http://www.aboutyun.com/thread-7374-1-1.html

  4. 爬虫mm131明星照片

    ''' 1. 爬取以下站点中各个明星图片,分别单独建文件夹存放. 起始URL地址:http://www.mm131.com/mingxing ''' import os import logging ...

  5. NYOJ 食物链(WA)

    1.WA代码 思路:预先分好3类,对每一行数据进行分类和真话假话判断 WA原因:前面某些行的数据 需要依赖 后面某些行给的数据 才能进行分类 初步改正思路( 对于前面给的无法直接分类的数据进行记录,等 ...

  6. js小数点精度问题

    项目背景是用eharts 渲染数据,其中Y 轴的 刻度尺间隔用 interval,代码中如下: yAxis: [ { type : 'value', position:'left', min:minV ...

  7. poi 生成图片到excel

    try { InputStream iss = new FileInputStream("D:\\test.xlsx"); XSSFWorkbook wb = new XSSFWo ...

  8. 向数据库中添加数据,通过se16 不能添加,通过 代码可以添加的原因

    1:  在向数据库中添加数据时,通过客户端se16 准备对 数据表进行添加数据,提示如下: 找了以下原因,如下: https://www.baidu.com/link?url=3yRtAfY1_9XG ...

  9. [django]python异步神器-celery

    python异步神器celery https://segmentfault.com/a/1190000007780963

  10. 1A

    #include <iostream> using namespace std; int main() { long long n, m, a, r, c; cin>>n> ...