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

1212
12345666
1235
END

Sample Output

2
2
0
 //2016.8.20
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 20
using namespace std; int ans, num[N][N], n;//num[i][j]用来记录从i到j位,数字的大小。
char s[N]; void dfsR(int pos, int leftsum, int rightsum)
{
if(pos == n && leftsum == rightsum){
ans++; return;
}
if(leftsum < rightsum)return;//剪枝
for(int i = pos; i < n; i++)
dfsR(i+, leftsum, rightsum+num[pos][i]);
} void dfsL(int pos, int sum, int mid)//pos表示当前处理的位置,sum表示已处理的和,mid表示等号的位置。
{
if(pos == mid)//对左边dfs完后,对右边dfs
dfsR(mid, sum, );
for(int i = pos; i < mid; i++)//枚举加号位置。
dfsL(i+, sum+num[pos][i], mid);
}
int main()
{
while(scanf("%s", s)!=EOF)
{
if(s[] == 'E')break;
ans = ;
n = strlen(s);
for(int i = ; i < n; i++)
{
int tmp = ;
for(int j = i; j < n; j++)
{
tmp += s[j]-'';
num[i][j] = tmp;
tmp *= ;
}
}
for(int i = ; i < n; i++)//枚举等号的位置,然后暴搜
dfsL(, , i);
cout<<ans<<endl;
} return ;
}

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. C#读取word文件

    第一步:添加对在项目引用里添加上对Microsoft Word 11.0 object library的引用.右击--引用---在com标签下添加.

  2. EasyUI中dialog中嵌入form细节问题记录

    当代码如下: function myClear() { $("#add_form").form("reset"); $("#add_dialog&qu ...

  3. zookeoper在root下设置开机启动

    1 准备工作 1) 切换到/etc/rc.d/init.d/目录下 2) 创建zookeeper文件:touch zookeeper 3)更新权限:chmod +777 zookeeper 4)编辑文 ...

  4. (中等) POJ 2948 Martian Mining,DP。

    Description The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site ...

  5. keil mdk中如何确保某一段程序不被优化掉(转)

    源:keil mdk中如何确保某一段程序不被优化掉 使用mdk编程,假如有一个有用的函数你定义了但是没有显式的调用,mdk在默认方式下,将会把这个函数从整个程序总删除掉,以节省ROM. 比如,你在RO ...

  6. Extjs6中的新特性

    Ext JS在Sencha框架中引入了许多新的和令人兴奋的改进.这些变化为基于所有现代浏览器.设备和屏幕尺寸带来了新的功能和可用性. 工具包(ToolKits) Ext JS 6最大的变化就是将Ext ...

  7. thinkphp所有参数配置

    /* 项目设定 */ 'APP_DEBUG' => false, // 是否开启调试模式 'APP_DOMAIN_DEPLOY' => false, // 是否使用独立域名部署项目 'AP ...

  8. AFNetworking content type not support

    ref:http://blog.csdn.net/nyh1006/article/details/25068255 1.错误信息:Error:Error Domain=AFNetworkingErro ...

  9. JQueryUI确认框 confirm

    $(function(){ $('#AlertMsg').dialog({ autoOpen: false, width: 300, modal: true, position: 'center', ...

  10. EF的join用法

    var customers = DB.Customer.Join(DB.Commission, cst => cst.CommissionId,                          ...