hdu4403A very hard Aoshu problem 线段树
//给一个长度为大于2小于15的字符串
//在当中间加‘+’或‘=’使得其成为一个等式的方法的个数
//枚举等号位置。暴力搜索加号加的位置
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 20;
typedef __int64 ll ;
int ans;
int a[maxn] ,len_a;
int b[maxn] , len_b ;
char str[maxn] , len;
bool judge(int pos)
{
ll ans_1 = 0 ,ans_2 = 0;
int pre = 1 ;
for(int i = 1;i <= len_a;i++)
{
ll temp = 0;
for(int j = pre ; j <= (i == len_a ? pos :a[i]) ; j++)
temp = temp*10 + str[j - 1] - '0' ;
ans_1 += temp ;
pre = a[i] + 1 ;
}
pre = pos + 1 ;
for(int i = 1;i <= len_b ;i++)
{
ll temp = 0 ;
for(int j = pre ; j <= (i == len_b?
len :b[i]) ;j++)
temp = temp*10 + str[j - 1] - '0' ;
ans_2 += temp ;
pre = b[i] + 1 ;
}
return (ans_1 == ans_2);
}
void dfs(int pos , int step)
{
if(step == (len))
{
if(judge(pos))
ans ++ ;
return ;
}
if(step < pos)
{
a[len_a++] = step ;
dfs(pos , step+1) ;
len_a--;
}
if(step > pos)
{
b[len_b++] = step ;
dfs(pos , step+1) ;
len_b-- ;
}
dfs(pos , step+1) ;
}
int main()
{
//freopen("in.txt" , "r" , stdin) ;
while(scanf("%s" ,str))
{
if(str[0] == 'E')
break;
len = strlen(str) ;
ans = 0 ;len_a = len_b = 1 ;
for(int i = 1;i < len ;i++)
dfs(i , 1) ;
printf("%d\n" , ans) ;
}
return 0 ;
}
hdu4403A very hard Aoshu problem 线段树的更多相关文章
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- Codeforces 803G Periodic RMQ Problem 线段树
Periodic RMQ Problem 动态开点线段树直接搞, 我把它分成两部分, 一部分是原来树上的, 一部分是后来染上去的,两个部分取最小值. 感觉有点难写.. #include<bits ...
- Codeforces 903G Yet Another Maxflow Problem - 线段树
题目传送门 传送门I 传送门II 传送门III 题目大意 给定一个网络.网络分为$A$,$B$两个部分,每边各有$n$个点.对于$A_{i} \ (1\leqslant i < n)$会向$A_ ...
- bzoj 3489 A simple rmq problem - 线段树
Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一次的数,并且要求找的这个数尽可能大.如果找不到这样的数,则直 ...
- spoj IITWPC4F - Gopu and the Grid Problem 线段树
IITWPC4F - Gopu and the Grid Problem no tags Gopu is interested in the integer co-ordinates of the ...
- 【CF903G】Yet Another Maxflow Problem 线段树
[CF903G]Yet Another Maxflow Problem 题意:一张图分为两部分,左边有n个点A,右边有m个点B,所有Ai->Ai+1有边,所有Bi->Bi+1有边,某些Ai ...
- FZU2013 A short problem —— 线段树/树状数组 + 前缀和
题目链接:https://vjudge.net/problem/FZU-2013 Problem 2013 A short problem Accept: 356 Submit: 1083Ti ...
- hud-5475 An easy problem(线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- ZOJ-3686 A Simple Tree Problem 线段树
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3686 题意:给定一颗有根树,每个节点有0和1两种值.有两种操作: ...
随机推荐
- libjpeg的问题
游戏项目是基于cocos2d-x开发的,但线上发现一个bug就是玩家在设置完自定义头像后直接闪退.凡是在设置该玩家头像的地方,游戏就直接闪退.最终定位到的问题是图片数据源有问题,我的机器是win7,图 ...
- zoj2334 Monkey King , 并查集,可并堆,左偏树
提交地址:点击打开链接 题意: N(N<=10^5)仅仅猴子,初始每仅仅猴子为自己猴群的猴王.每仅仅猴子有一个初始的力量值.这些猴子会有M次会面. 每次两仅仅猴子x,y会面,若x,y属于同一个 ...
- Spring MVC+Mybatis 多数据源配置
文章来自:https://www.jianshu.com/p/fddcc1a6b2d8 1. 继承AbstractRoutingDataSource AbstractRoutingDataSource ...
- MySQL 查询优化简记
今天尝试对一张MySQL表做查询优化, 500W数据 但是发现加了索引比不加索引使用全表扫描还慢, 上网查, 据说是因为需要回表, 因为没有用到 using index(覆盖索引), 而回表查询是随机 ...
- hdu 2544 单源最短路问题 dijkstra+堆优化模板
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- rapidjson库的基本使用
转自:https://blog.csdn.net/qq849635649/article/details/52678822 我在工作中一直使用的是rapidjson库,这是我在工作中使用该库作的一些整 ...
- CListCtrl 之右键菜单
在使用CListCtrl时要为它添加一个右键菜单,步骤如下: 1. 响应CListCtrl的NM_RCLICK消息. 2. 添加一个菜单资源,在菜单资源中插入要添加到菜单内容. 一般存在两种方法: ...
- [leetcode]Remove Duplicates from Sorted Array II @ Python
原题地址:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 题意: Follow up for &quo ...
- [leetcode]Jump Game @ Python
原题地址:https://oj.leetcode.com/problems/jump-game/ 题意: Given an array of non-negative integers, you ar ...
- .NET程序性能优化的基本要领
Bill Chiles(Roslyn编译器的程序经理)写了一篇文章<Essential Performance Facts and .NET Framework Tips>,知名博主寒江独 ...