A very hard Aoshu problem

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Aoshu is very popular among primary school students. It is mathematics, but much harder than ordinary mathematics for primary school students. Teacher Liu is an Aoshu teacher. He just comes out with a problem to test his students:

Given a serial of digits, you must put a '=' and none or some '+' between these digits and make an equation. Please find out how many equations you can get. For example, if the digits serial is "1212", you can get 2 equations, they are "12=12" and "1+2=1+2". Please note that the digits only include 1 to 9, and every '+' must have a digit on its left side and right side. For example, "+12=12", and "1++1=2" are illegal. Please note that "1+11=12" and "11+1=12" are different equations.

Input

There are several test cases. Each test case is a digit serial in a line. The length of a serial is at least 2 and no more than 15. The input ends with a line of "END". 

Output

For each test case , output a integer in a line, indicating the number of equations you can get. 

Sample Input

  1. 1212
  2. 12345666
  3. 1235
  4. END

Sample Output

  1. 2
  2. 2
  3. 0
  1. //2016.8.20
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #define N 20
  6. using namespace std;
  7.  
  8. int ans, num[N][N], n;//num[i][j]用来记录从i到j位,数字的大小。
  9. char s[N];
  10.  
  11. void dfsR(int pos, int leftsum, int rightsum)
  12. {
  13. if(pos == n && leftsum == rightsum){
  14. ans++; return;
  15. }
  16. if(leftsum < rightsum)return;//剪枝
  17. for(int i = pos; i < n; i++)
  18. dfsR(i+, leftsum, rightsum+num[pos][i]);
  19. }
  20.  
  21. void dfsL(int pos, int sum, int mid)//pos表示当前处理的位置,sum表示已处理的和,mid表示等号的位置。
  22. {
  23. if(pos == mid)//对左边dfs完后,对右边dfs
  24. dfsR(mid, sum, );
  25. for(int i = pos; i < mid; i++)//枚举加号位置。
  26. dfsL(i+, sum+num[pos][i], mid);
  27. }
  28. int main()
  29. {
  30. while(scanf("%s", s)!=EOF)
  31. {
  32. if(s[] == 'E')break;
  33. ans = ;
  34. n = strlen(s);
  35. for(int i = ; i < n; i++)
  36. {
  37. int tmp = ;
  38. for(int j = i; j < n; j++)
  39. {
  40. tmp += s[j]-'';
  41. num[i][j] = tmp;
  42. tmp *= ;
  43. }
  44. }
  45. for(int i = ; i < n; i++)//枚举等号的位置,然后暴搜
  46. dfsL(, , i);
  47. cout<<ans<<endl;
  48. }
  49.  
  50. return ;
  51. }

HDU4403(暴搜)的更多相关文章

  1. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] ...

  2. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

  3. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  4. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  5. Sicily1317-Sudoku-位运算暴搜

    最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...

  6. codeforces 339C Xenia and Weights(dp或暴搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weig ...

  7. Usaco 2.3 Zero Sums(回溯DFS)--暴搜

    Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...

  8. suoi62 网友跳 (暴搜+dp)

    传送门 sbw太神啦orz 首先N<=20可以直接暴搜 然后玄学剪枝可以过18个点 那么N<=40的时候,就把它拆成两半分别暴搜,再用dp拼起来 对于前半段,设f[i][j]是开始高度为i ...

  9. bzoj1016/luogu4208 最小生成树计数 (kruskal+暴搜)

    由于有相同权值的边不超过10条的限制,所以可以暴搜 先做一遍kruskal,记录下来每个权值的边使用的数量(可以离散化一下) 可以证明,对于每个权值,所有的最小生成树中选择的数量是一样的.而且它们连成 ...

随机推荐

  1. Java 8新特性探究(八)精简的JRE详解

    http://www.importnew.com/14926.html     首页 所有文章 资讯 Web 架构 基础技术 书籍 教程 Java小组 工具资源 - 导航条 - 首页 所有文章 资讯 ...

  2. UWSGITOP-----监控uwsgi 性能

    启动 uwsgi -x etc/bfdds_cookiemapping_conf.xml --stats /tmp/stats.socket 查看 uwsgitop /tmp/stats.socket ...

  3. 三种Dataase Mapping的系统架构

    ORM - O/R M - Object/Relational Mapping: A technique/idea used to map objects and thier individual r ...

  4. Unity3d 开发之 ulua 坑的总结

    相同的 lua 代码在安卓上能正常运行,但在 IOS 上可能不会正常运行而导致报红,崩溃等,我在使用 lua 编程时遇到的一些坑总结如下: 1. File.ReadAllText, 诸如以下代码在 i ...

  5. 如何在Eclipse中安装PDT插件来开发PHP

    之前查过很多PDT的安装方法,60%都是让人直接安装All-in-one的PHP eclipse版本,纯属让人无语,而有些给出的PDT安装链接无法正确下载插件,对此,给出了我安装过的PDT插件下载地址 ...

  6. STM32驱动TEA5767收音机模块

    Tea5767是飞利浦公司出的一款集成化的收音机芯片,大四的时候机缘巧合遇到了这个芯片,用了一下,写点资料 主要特性 TEA5767HN是一款低功耗立体声收音IC,广泛应用于手机MP3 .MP 4 播 ...

  7. iOS 获取本地文件的各种坑

    1.无论:TXT,EPUB,PDF等各种格式的文件,保存到本地的时候,最好都保存成字母或者数字,不要保存成汉字,否则,在取文件的时候,由于编码的问题,各种瓦特 2.如果文件名真的保存成了汉字,那么进行 ...

  8. css(二) block,inline和inline-block概念和区别

    转: http://www.cnblogs.com/KeithWang/p/3139517.html 总体概念 block和inline这两个概念是简略的说法,完整确切的说应该是 block-leve ...

  9. C#中BASE64和图片相互转换

    //图片 转为    base64编码的文本        private void button1_Click(object sender, EventArgs e)        {        ...

  10. sql语句:if exists语句使用

    ') begin print('exists ') end else begin print('no exists ') end go