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,记录下来每个权值的边使用的数量(可以离散化一下) 可以证明,对于每个权值,所有的最小生成树中选择的数量是一样的.而且它们连成 ...
随机推荐
- ural1628 White Streaks
White Streaks Time limit: 1.0 secondMemory limit: 64 MB The life of every unlucky person has not onl ...
- 计算机学院大学生程序设计竞赛(2015’12) 1002 Polygon
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #inclu ...
- 解决airserver在Windows下安装失败的问题
airserver 可以将iphone 实时投影到mac 和 pc.在mac上安装非常简单.但是在Windows上安装时会有很多问题.之前我电脑安装很快就完成了(因为我之前已经在不知情的前提先事先装过 ...
- [转] WebService开发笔记 1 -- 利用cxf开发WebService竟然如此简单
以下文章来自 http://www.blogjava.net/jacally/articles/186655.html 现在的项目中需要用到SOA概念的地方越来越多,最近我接手的一个项目中就提出了 ...
- java类固定值代替基表写法
package cn.com.mcd.enumeration; public enum AuditStatusEnum { NOTAUDIT("0", "未审核" ...
- POJ3255次短路
POJ3255 题意:给定一个图,求从1到n的次短路 分析:我们需要在dijkstra上作出一些修改,首先,到某个顶点v的次短路要么是到其他某个顶点u的最短路在加上u到v的边,要么是到v的次短路再加上 ...
- Android之Margin和Padding属性及支持的长度单位
做了个小软件后,终于把Margin和Padding弄清楚了,现总结如下: Android的Margin和Padding跟Html的是一样的.如下图所示:黄色部分为Padding,灰色部分为Margin ...
- Java6 WebService学习
首先,建立一个WebService: package garfield; import javax.jws.WebService; import javax.xml.ws.Endpoint; @Web ...
- TCP/IP 标志位 SYN ACK RST UTG PSH FIN
三次握手:发送端发送一个SYN=1,ACK=0标志的数据包给接收端,请求进行连接,这是第一次握手:接收端收到请求并且允许连接的话,就会发送一个 SYN=1,ACK=1标志的数据包给发送端,告诉它,可以 ...
- PopupWindow的基本使用
1>写好布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...