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两种值.有两种操作: ...
随机推荐
- SharePoint 取消分享时的默认发邮件
前言 最近遇到一个需求,就是sharepoint默认分享的时候,会默认勾选发送邮件的功能.而用户,经常会用到分享的功能,但是不需要发送邮件,需要默认不勾选这个操作. 这样,就需要修改sharepoin ...
- 在websocket中怎么样注入service类
最近项目中用到了websocket,遇到很多问题,其中一个是@ServerEndpoint修饰的类无法注入其他的bean,注入的对象都是null,在网上找了好多资料,无意中发现一个朋友的答案给了思路. ...
- TK1 设置最大频率
支持的值:cat /sys/kernel/debug/clock/gbus/possible_rates当前值:cat /sys/kernel/debug/clock/gbus/rate 设置最大值: ...
- HTML5 本地文件操作之FileSystemAPI实例(三)
文件夹操作demo 1.读取根目录文件夹内容 window.requestFileSystem = window.requestFileSystem || window.webkitRequestFi ...
- fabric 清理环境 运行SDK
清理环境: rm -rf /tmp/* rm -rf ~/.hfc-key-store/ 启动网络: docker ps -a create channel: join channel: 清理npm ...
- linux下使用ack进行代码搜索
1.安装 wget http://beyondgrep.com/ack-2.12-single-file sudo mv ack-2.12-single-file /usr/bin/ack sudo ...
- linux 比较两个文件夹不同 (diff命令, md5列表)
比较文件夹diff,可以直接使用diff命令 [root@~]# diff -urNa dir1 dir2 -a Treat all files as text and compare them li ...
- Windbg简明教程(转)
Windbg是Microsoft公司免费调试器调试集合中的GUI的调试器,支持Source和Assembly两种模式的调试.Windbg不仅可以调试应用程序,还可以进行Kernel Debug(新版本 ...
- 算法 数组中出现次数最多的数字 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 构建-13 Analyzer APK文件分析
官方文档 使用APK Analyzer分析您的构建 [Analyze your build with APK Analyzer] Android Studio包含一个APK分析器,可在构建过程完成后 ...