题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5938

题意:给出一个长度最大是2020的数字串, 你要把数字串划分成55段, 依次填入’+’, ’-’, ’*’, ’/’, 问能得到的最大结果。

想让这个结果最大,那尽可能让减号左边的数最大,只需要关心左边的第一位是一个数还是最后一位是一个数,后面的枚举*和/的位置就行了。

 #include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int maxn = ;
LL ret, dret;
int n;
char s[maxn]; void dfs(int pos, int cnt, LL c, LL d, LL e) {
if(pos >= n) return;
if(cnt == ) {
dret = min(dret, c * d / e);
return;
}
if(cnt == ) {
LL tmp = ;
for(int i = pos; i < n; i++) {
tmp *= ; tmp = tmp + s[i] - '';
dfs(i+,cnt+, tmp,d,e);
}
}
if(cnt == ) {
LL tmp = ;
for(int i = pos; i < n; i++) {
tmp *= ; tmp = tmp + s[i] - '';
dfs(i+,cnt+,c,tmp,e);
} }
if(cnt == ) {
LL tmp = ;
for(int i = pos; i < n; i++) {
tmp *= ; tmp = tmp + s[i] - '';
}
dfs(-,cnt+,c,d,tmp);
}
} int main() {
// freopen("in", "r", stdin);
int T, _ = ;
scanf("%d", &T);
while(T--) {
scanf("%s", s);
n = strlen(s);
ret = -((LL) << );
for(int i = ; i < n-; i++) {
LL x = ;
LL y = ;
LL s1 = , s2 = , ss = ;
int j = ;
while(j < i) {
x *= ;
x = x + s[j++] - '';
}
y = s[i] - '';
s1 = x + y;
j = ;
x = s[] - ''; y = ;
while(j <= i) {
y *= ;
y = y + s[j++] - '';
}
s2 = x + y;
ss = max(s1, s2);
dret = (LL) << ;
dfs(i+, , , , );
ret = max(ret, ss-dret);
}
printf("Case #%d: ", _++);
printf("%I64d\n", ret);
}
return ;
}

[HDOJ5938]Four Operations(暴力,DFS)的更多相关文章

  1. hihoCoder 1185 连通性·三(Tarjan缩点+暴力DFS)

    #1185 : 连通性·三 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 暑假到了!!小Hi和小Ho为了体验生活,来到了住在大草原的约翰家.今天一大早,约翰因为有事要出 ...

  2. Strange Country II 暴力dfs

    这题点的个数(<=50)有限, 所以可以纯暴力DFS去搜索 //#pragma comment(linker, "/STACK:16777216") //for c++ Co ...

  3. UVA129 暴力dfs,有许多值得学习的代码

    紫书195 题目大意:给一个困难的串,困难的串的定义就是里面没有重复的串. 思路:不需要重新对之前的串进行判重,只需要对当前的加入的字符进行改变即可. 因为是判断字典序第k个的字符串,所以要多一个全局 ...

  4. 2018杭电多校第五场1002(暴力DFS【数位】,剪枝)

    //never use translation#include<bits/stdc++.h>using namespace std;int k;char a[20];//储存每个数的数值i ...

  5. A. The Fault in Our Cubes 暴力dfs

    http://codeforces.com/gym/101257/problem/A 把它固定在(0,0, 0)到(2, 2, 2)上,每次都暴力dfs检查,不会超时的,因为规定在这个空间上,一不行, ...

  6. Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)

    题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...

  7. UVA 185(暴力DFS)

      Roman Numerals  The original system of writing numbers used by the early Romans was simple but cum ...

  8. 1172: 单词接龙(XCOJ 暴力DFS)

    1172: 单词接龙 时间限制: 1 Sec  内存限制: 128 MB提交: 12  解决: 5 标签提交统计讨论版 题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词 ...

  9. 1506 传话 (暴力DFS或者Tarjan模板题)

    题目描述 Description 一个朋友网络,如果a认识b,那么如果a第一次收到某个消息,那么会把这个消息传给b,以及所有a认识的人. 如果a认识b,b不一定认识a. 所有人从1到n编号,给出所有“ ...

随机推荐

  1. Intent跳转传list集合

    先把List<>改为ArrayList<> ArrayList<Good> list=new ArrayList<Good>(); Intent int ...

  2. 《HTML5高级程序设计》知识点概要(不涉及详细语法)

    不断更新. 说明:主要记录html5中的一些注意点或知识点,尽量不涉及具体语法信息. 一.CANVAS: 检测: try{ document.createElement("canvas&qu ...

  3. java的web项目中使用cookie保存用户登陆信息

    本文转自:http://lever0066.iteye.com/blog/1735963 最近在编写论坛系统的实现,其中就涉及到用户登陆后保持会话直到浏览器关闭,同时可以使用cookie保存登陆信息以 ...

  4. LUA之面向对象

    Account = { balance=0, withdraw = function (self, v) self.balance = self.balance - v end } function ...

  5. Calendar的问题

    1. include file is not work now. remove <!-- #include file="Calendar.js" -->, add &l ...

  6. Java中的TreeMap、Comparable、Comparator

    我们知道HashMap的存储位置是按照key这个对象的hashCode来存放的,而TreeMap则是不是按照hashCode来存放,他是按照实现的Comparable接口的compareTo这个方法来 ...

  7. HDU 5950:Recursive sequence(矩阵快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:给出 a,b,n,递推出 f(n) = f(n-1) + f(n-2) * 2 + n ^ 4. f ...

  8. SpringMVC项目,启动项目怎么总是报找不到log4j.properties文件

    具体操作:右键项目---->properties--->Java Build Path--->source--->Add Folder --->选择log4.proper ...

  9. mysqldump备份过程中都干了些什么

    mysqldump备份方便,易读,功能丰富,相信大家都有 使用过这个命令进行备份,但是这个命令在备份的过程中都做了写什么呢,下面打开general_log进行查看: 1.登录mysql命令行客户端: ...

  10. python8

    编译和解释性语言的区别 编译 典型的C C++ 编译完成之后是可执行文件. 机器码-底层(外文书,但是不懂中文,翻译成中文就可以看) 解释性语言----看一句英文书,让翻译解释一句 解释器写的代码便于 ...