题目链接: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 ;
}

最新文章

  1. 漫谈C++11 Thread库之原子操作
  2. args[0]
  3. 写出易调试的SQL—西科软件
  4. andorid SQLite数据库的增删改查 和事务操作
  5. HTML5中的Canvas精品教程
  6. 如何使用命令提示符进入mysql
  7. HDU 4921 Map
  8. &lt;EditText /&gt; This text field does not specify an inputType or a hint
  9. POJ 2653 Pick-up sticks
  10. 手机cpu结构,arm
  11. Android: Only the original thread that created a view hierarchy can touch its views 异常
  12. Jstack定位CPU使用最多的线程及代码
  13. Vagrant测试
  14. Java实现图片添加水印
  15. 3.控制hive map reduce个数
  16. 查看gcc的默认宏定义命令【转】
  17. GIS(一)——在js版搜索地图上加入Marker标记
  18. 按钮CSS样式
  19. Zookeeper之Curator(1)客户端对节点的一些监控事件的api使用
  20. [Algorithms] Heap and Heapsort

热门文章

  1. s3c2440 lcd 显示图片裸机程序
  2. 【python cookbook】【字符串与文本】1.针对任意多的分隔符拆分字符串
  3. windows cmd command line 命令
  4. 常用Git命令
  5. linux cache and buffer【转】
  6. Linux workqueue工作原理 【转】
  7. uniq DEMO
  8. 如何扩大ImageView的点击区域
  9. 【转】在Eclipse中配置tomcat
  10. [团队项目]sprint3 &amp; 团队贡献分。