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两种值.有两种操作: ...
随机推荐
- SpringBoot下的Job定时任务
编写Job定时执行任务十分有用,能解决很多问题,这次实习的项目里做了一下系统定时更新三方系统订单状态的功能,这里用到了Spring的定时任务使用的非常方便,下面总结一下如何使用: 一,@schedul ...
- fabric-ca-server
fabric-ca-server start -b admin:adminpw -d --db.type mysql --db.datasource "root:rootpwd@tcp(17 ...
- The "Out of socket memory" error
The "Out of socket memory" error I recently did some work on some of our frontend machines ...
- HTTP协议学习【转】
面试过程中又一个常见的问题,http协议,因为做服务器开发如果用http协议的话,现在各种开源软件都封装好了,python中只需要简单的继承定义好的类,重写get或者post等方法,几行代码就可以搭建 ...
- 【转】QT中QDataStream中浮点数输出问题
先上代码: C/C++ code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 int main(int argc, char *argv[]) { QApplicati ...
- 我一直跑的分类LSTM模型原来是这一个,新闻分类网络
原始的github可以参考这里: https://github.com/FudanNLP/nlpcc2017_news_headline_categorization 我的经验文章可以参考这里: ht ...
- go语言之进阶篇显式调用panic函数
1.显式调用panic函数 示例: package main import "fmt" func testa() { fmt.Println("aaaaaaaaaaaaa ...
- iOS开发文件夹--Copy items if needed
蓝色文件夹 蓝色文件夹(folder)一般作为资源文件夹使用,与黄色文件夹的主要区别是不参与编译,所以说如果你在这些文件夹下编写的逻辑代码是不参与编译的,其他文件也不能直接引用它们,若引用其中文件需要 ...
- [leetcode]Valid Palindrome @ Python
原题地址:https://oj.leetcode.com/problems/valid-palindrome/ 题意: Given a string, determine if it is a pal ...
- 超酷实用的jQuery焦点图赏析及源码
焦点图应用在现代网页中使用十分广泛,有注重简单小巧的,也有注重华丽美观的,大部分jQuery焦点图都可以滑动和切换图片,并且在切换图片时产生不同的动画特效.今天我们要分享一些超酷而且实用的jQuery ...