HDU4403(暴搜)
A very hard Aoshu problem
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
Output
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(暴搜)的更多相关文章
- 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜
3033: 太鼓达人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 204 Solved: 154[Submit][Status][Discuss] ...
- c++20701除法(刘汝佳1、2册第七章,暴搜解决)
20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 输入正整数n,按从小到大的顺序输出所有 ...
- 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 ...
- poj 3080 Blue Jeans(水题 暴搜)
题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...
- Sicily1317-Sudoku-位运算暴搜
最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...
- codeforces 339C Xenia and Weights(dp或暴搜)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Xenia and Weights Xenia has a set of weig ...
- 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 ... ...
- suoi62 网友跳 (暴搜+dp)
传送门 sbw太神啦orz 首先N<=20可以直接暴搜 然后玄学剪枝可以过18个点 那么N<=40的时候,就把它拆成两半分别暴搜,再用dp拼起来 对于前半段,设f[i][j]是开始高度为i ...
- bzoj1016/luogu4208 最小生成树计数 (kruskal+暴搜)
由于有相同权值的边不超过10条的限制,所以可以暴搜 先做一遍kruskal,记录下来每个权值的边使用的数量(可以离散化一下) 可以证明,对于每个权值,所有的最小生成树中选择的数量是一样的.而且它们连成 ...
随机推荐
- IFeatureWorkspace OpenFeatureClass Example(转)
网络来源:http://changqingnew.blog.163.com/blog/static/1075233820103383633639/ //IFeatureWorkspace OpenFe ...
- swift 自学小计
返回多个value func Myfunc()->(double,double,double) { return (3.14,2.33,9.88) } 动态参数 func Myfunc(numb ...
- Education Round16
A题:题意:给定国际象棋king的坐标,求能向几个方向移动分析:处理一下边界情况,其他的都是8 #include <iostream> #include <cstdio> #i ...
- C++异常(exception)第三篇-------如何释放资源(没有finally语句)
问题: C++中没有finally,那么应该在哪里关闭资源? C++的try{}catch(){},为什么没有finally{}块来释放资源? 如类中的一个方法,局部变量 File * file=NU ...
- arduino pro mini不能下载
刚毕业时就知道arduino,但当时崇拜技术极致,喜欢把单片机的性能用到尽,觉得操作寄存器运行效率高,对arduino 这种高效模式贬为投机取巧,不过其中也一直对arduino 有关注. 随着芯片技术 ...
- VC2010编写Dll文件(转)
源:VC2010编写Dll文件 1. 打开VS2010[Flie / New / Project / Visual C++ / Win32 / Win32 Console Application]在下 ...
- MapReduce 矩阵相乘
对于矩阵A[mn]*B[nl]=C[ml].这里可以并行起来的就是每个Cij,对于Cij而言,他是由A的第i行和B的第j列相乘得到.由于大的矩阵中经常是稀疏矩阵,所以一般用行列值表示 例如对于A: 1 ...
- ASIHTTPRequest异步请求
我们运行程序,如果网速很慢,查询的时候会一直黑屏,直到请求结束画面才出现,这样用户体验很不好.因此同步请求一般只是在某个子线 程中使用,而不在主线程中使用.异步请求的用户体验要比同步请求好,因此一般情 ...
- jquery遍历二维数组
function eachTowArray() { var ar = [[1,2,3],[4,5,6],[7,8,9]]; var result=""; //结果存放变量 ...
- java实现gbdt
DATA类 import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import ...