题目链接: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. ASP.NET MVC4中的bundles特性引发服务器拒绝访问(403错误)

    在ASP.NET MVC4中微软引入了bundles特性,这个特性可以将服务器端的多个Javascript或多个css文件捆绑在一起作为一个单一的URL地址供客户端浏览器调用,从而减少了页面上Http ...

  2. zabbix agent 类型自带的key

    zabbix服务器端通过与zabbix agent通信来获取客户端服务器的数据,agent分为两个版本,在配置主机我们可以看到一个是agent,另一个是agent(active). agent:zab ...

  3. HttpContext.Current.Cache在控制台下不工作

    说明: Cache 类不能在 ASP.NET 应用程序外使用.它是为在 ASP.NET 中用于为 Web 应用程序提供缓存而设计和测试的.在其他类型的应用程序(如控制台应用程序或 Windows 窗体 ...

  4. OC基础数据类型-NSData

    1.NSData,数据,当我们需要把一些信息写入到文件里或发送到网络上,我们需要把这些数据转换下,变成纯粹的0.1字符流 1 NSString * str = @"hello, world! ...

  5. keepalived + nginx双主 实战

    安装nginx nginx 下载地址 http://nginx.org/download/nginx-1.8.0.tar.gz 安装nginx的依赖关系 yum install pcre pcre-d ...

  6. hdwik中view模块的应用

    概述        MVC中的视图view 主要负责页面显示部分,所有的页面显示全部在此实现,视图对整个页面负责,它通过control的调用来显示页面和数据.视图(view)类template.cla ...

  7. 【转】MYSQL入门学习之三:全文本搜索

    转载地址:http://www.2cto.com/database/201212/173873.html 一.理解全文本搜索   www.2cto.com   1.MyISAM支持全文本搜索,而Inn ...

  8. c# Beginlnvoke 委托

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. LA 4126 Password Suspects

    问题描述:给定m个模式串,计数包含所有模式串且长度为n的字符串的数目. 数据范围:模式串长度不超过10,m <= 10, n <= 25,此外保证答案不超过1015. 分析:既然要计数给定 ...

  10. 迷之节约 分类: sdutOJ 最小生成树 2015-06-24 19:10 10人阅读 评论(0) 收藏

    迷之节约 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 FF超级有钱,最近又买了n个(1 <= n <= 300)小岛,为 ...