B. Smallest number

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/55/problem/B

Description

Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers abcd on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations.

Input

First line contains four integers separated by space: 0 ≤ a, b, c, d ≤ 1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication)

Output

Output one integer number — the minimal result which can be obtained.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Sample Input

1 1 1 1
+ + *

Sample Output

3

HINT

题意

给你4个数,然后给你三个符号,问你怎么安排着4个数的顺序,可以使得最后的答案最小

4个数和三个符号,选两个数和第一个符号出来,得到一个数

3个数和2个符号,选两个数和第二个符号出来,得到一个数

2个数和1个符号,得到答案

要求使得答案最小

题解:

暴力枚举。。。

代码:

#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std; long long ans = 1LL<<;
char S[];
void solve2(long long a,long long b) {
long long x = (S[] == '+') ? (a + b) : (a * b);
if (ans > x) {
ans = x;
}
}
void solve3(long long a,long long b,long long c) {
if (S[] == '+') {
solve2(a + b, c);
solve2(a + c, b);
solve2(b + c, a);
} else {
solve2(a * b, c);
solve2(a * c, b);
solve2(b * c, a);
}
}
void solve4(long long a,long long b,long long c,long long d) {
if (S[] == '+') {
solve3(a + b, c, d);
solve3(a + c, b, d);
solve3(a + d, b, c);
solve3(b + c, a, d);
solve3(b + d, a, c);
solve3(c + d, a, b);
} else {
solve3(a * b, c, d);
solve3(a * c, b, d);
solve3(a * d, b, c);
solve3(b * c, a, d);
solve3(b * d, a, c);
solve3(c * d, a, b);
}
} int main() {
long long a, b, c, d;
cin>>a>>b>>c>>d;
for(int i=;i<=;i++)
cin>>S[i];
solve4(a,b,c,d);
cout<<ans<<endl;
}

Codeforces Beta Round #51 B. Smallest number dfs的更多相关文章

  1. Codeforces Beta Round #51 D. Beautiful numbers 数位dp

    D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...

  2. Codeforces Beta Round #51 C. Pie or die 博弈论找规律 有趣的题~

    C. Pie or die Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem/ ...

  3. Codeforces Beta Round #51 A. Flea travel 水题

    A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...

  4. Codeforces Beta Round #51 D. Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  5. Codeforces Beta Round #51 D. Beautiful numbers(数位dp)

    题目链接:https://codeforces.com/contest/55/problem/D 题目大意:给你一段区间[l,r],要求这段区间中可以整除自己每一位(除0意外)上的数字的整数个数,例如 ...

  6. codeforces 55d//Beautiful numbers// Codeforces Beta Round #51

    题意:一个数能整除它所有的位上的数字(除了0),统计这样数的个数. 注意离散化,为了速度更快需存入数组查找. 不要每次memset,记录下已有的长度下符合条件的个数. 数位dp肯定是从高位到低位. 记 ...

  7. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  8. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  9. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

随机推荐

  1. Squid故障

    1.COSS will not function without large file support (off_t is 4 bytes long. Please reconsider recomp ...

  2. MySQL基础之第8章 视图

    8.1.视图简介 视图由数据库中的一个表,视图或多个表,视图导出的虚拟表.其作用是方便用户对数据的操作. 8.2.创建视图必须要有CREATE VIEW 和 SELECT 权限SELECT selec ...

  3. android 应用页面与数据申请逻辑剥离;

    1.页面与数据申请剥离,数据申请框架可以灵活更换,解耦合: 2.对应页面的数据申请类中,将返回数据解析剥离,灵活更换数据返回及对应解析: 二.模块划分: 1.一些通用的工具类,可以考虑迁移到com.c ...

  4. POJ 1251 Jungle Roads

    题意:嗯……没看题……看了眼图……求个最小生成树. 解法:kruskal. 代码: #include<stdio.h> #include<iostream> #include& ...

  5. C# 多线程网络爬虫

    原文 C#制作多线程处理强化版网络爬虫 上次做了一个帮公司妹子做了爬虫,不是很精致,这次公司项目里要用到,于是有做了一番修改,功能添加了网址图片采集,下载,线程处理界面网址图片下载等. 说说思路:首相 ...

  6. Hadoop集群中Hbase的介绍、安装、使用

    导读 HBase – Hadoop Database,是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBase技术可在廉价PC Server上搭建起大规模结构化存储集群. 一.Hbase ...

  7. 改变DEV控件的字体 z

    改变所有的组件字体,使用AppearanceObject.DefaultFont属性:static void Main() {    DevExpress.Utils.AppearanceObject ...

  8. 为Fitnesse-20140630定制RestFixture代码

    摘要:Fitnesse插件RestFixture在最新版Fitnesse输出测试结果为html文本,而非html.本博文记录RestFixture定制代码的过程. 准备开发环境 假定你已经正确安装JD ...

  9. 【原】Storm 入门教程目录

    Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...

  10. 题目1437:To Fill or Not to Fill:贪心算法解决加油站选择问题(未解决)

    //贪心算法解决加油站选择问题 //# include<iostream> # include<stdio.h> using namespace std; # include& ...