A very hard Aoshu problem(dfs或者数位)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4403
A very hard Aoshu problem
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1080    Accepted Submission(s): 742
is very popular among primary school students. It is mathematics, but
much harder than ordinary mathematics for primary school students.
Teacher Liu is an Aoshu teacher. He just comes out with a problem to
test his students:
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.
are several test cases. Each test case is a digit serial in a line. The
length of a serial is at least 2 and no more than 15. The input ends
with a line of "END".
12345666
1235
END
2
0
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
char str[];
int val[][];
int len;
int ans; void cal()
{
memset(val,,sizeof(val));
for(int i = ; i < len ; i++)
for(int j = i ; j < len ; j++)
for(int k = i ; k <= j ; k++)
val[i][j] = val[i][j]*+(str[k]-'');
}
void dfsr(int lsum,int pos, int rsum)
{
if(pos>=len)
{
if(rsum==lsum)
ans++;
return ;
}
for(int k = pos+ ; k <= len ; k++)
dfsr(lsum,k,rsum+val[pos][k-]);
}
void dfsl(int equ , int pos , int lsum)
{
if(pos>=equ)
dfsr(lsum,equ,);
for(int k = pos+ ; k <= equ ; k++)
dfsl(equ,k,lsum+val[pos][k-]);
} int main()
{
while(~scanf("%s",str)&&str[]!='E')
{
ans = ;
len = strlen(str);
cal();
int equ;
for(equ = ; equ < len ; equ++)
dfsl(equ,,);
printf("%d\n",ans);
}
return ;
}
数位:
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define N 17
char a[N];
int equ;
int len;
bool ck(int sum)
{
int l= , r=;
int cur = ;
for(int i = ; i <= equ ;i++)
{
if(sum&(<<i)) {
cur = cur * + a[i]-'';
l+=cur;
cur = ;
}
else cur = cur*+a[i]-'';
}
if(cur != ) l+=cur;
cur = ;
for(int i = equ+ ; i< len ; i++)
{
if(sum&(<<i)){
cur = cur * + a[i]-'';
r+=cur;
cur = ;
}
else cur = cur*+a[i]-'';
}
if(cur!=) r += cur;
if(l==r) return true;
else return false;
}
int main()
{
while(~scanf("%s",a)&&a[]!='E')
{
int ans = ;
len = strlen(a);
for( equ = ; equ < len- ; equ++)
{
int tm = <<(len-);
for(int j = ; j < tm ;j++)
{
if(ck(j)){
ans++;
// printf("%d %d\n", equ, j);
}
}
}
printf("%d\n",ans>>);
}
return ;
}
A very hard Aoshu problem(dfs或者数位)的更多相关文章
- HDU 4403 A very hard Aoshu problem(DFS)
		
A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...
 - HDU4403   A very hard Aoshu problem DFS
		
A very hard Aoshu problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
 - hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0
		
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
 - HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)
		
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
 - HDOJ(HDU).1016 Prime Ring Problem (DFS)
		
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
 - HDU 4403 A very hard Aoshu problem(dfs爆搜)
		
http://acm.hdu.edu.cn/showproblem.php?pid=4403 题意: 给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子. 思路: 数据量比 ...
 - HDU 4403 A very hard Aoshu problem (DFS暴力)
		
题意:给你一个数字字符串.问在字符串中间加'='.'+'使得'='左右两边相等. 1212 : 1+2=1+2, 12=12. 12345666 : 12+3+45+6=66. 1+2+3+4 ...
 - CDOJ 483 Data Structure Problem DFS
		
Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...
 - A very hard Aoshu problem
		
A very hard Aoshu proble Problem Description Aoshu is very popular among primary school students. It ...
 
随机推荐
- 使用Libmicrohttpd搭建内嵌(本地)服务器
			
Libmicrohttpd简介 GNU Libmicrohttpd是一个用来在项目中内嵌http服务器的C语言库,它具有以下几个非常鲜明的特点: C语言库,小而快. API非常简单,且都是可重入的. ...
 - 读Zepto源码之assets模块
			
assets 模块是为解决 Safari 移动版加载图片过大过多时崩溃的问题.因为没有处理过这样的场景,所以这部分的代码解释不会太多,为了说明这个问题,我翻译了<How to work arou ...
 - go generate 生成代码
			
今后一段时间要研究下go generate,在官网博客上看了Rob Pike写的generating code,花了一些时间翻译了下.有几个句子翻译的是否正确有待考量,欢迎指正. 生成代码 通用计算的 ...
 - LeetCode题目总结(三)
			
我的代码在github上,https://github.com/WINTERFELLS/LeetCode-Answers 这里只提供个人的解题思路,不一定是最好的. 41-60: 给定一个排好序的数组 ...
 - ASP.NET Core学习之一 入门简介
			
一.入门简介 在学习之前,要先了解ASP.NET Core是什么?为什么?很多人学习新技术功利心很重,恨不得立马就学会了. 其实,那样做很不好,马马虎虎,联系过程中又花费非常多的时间去解决所遇到的“问 ...
 - K:二叉树的非递归遍历
			
相关介绍: 二叉树的三种遍历方式(先序遍历,中序遍历,后序遍历)的非递归实现,虽然递归方式的实现较为简单且易于理解,但是由于递归方式的实现受其递归调用栈的深度的限制,当递归调用的深度超过限制的时候, ...
 - jQuery 选择器 (一)
			
选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id="lastname" 的元素 .class $( ...
 - 移动端页面  css reset
			
这个是通用的 css reset.这个版本适用于 移动端页面 如果需要在 PC端使用,可以 修改 html{font-size: 10px;}为html{font-size: 12px;} 其他地方 ...
 - python3之xml&ConfigParser&hashlib&Subprocess&logging模块
			
1.xml模块 XML 指可扩展标记语言(eXtensible Markup Language),标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言. XML 被设计用来传输和存储 ...
 - Shell和命令基础
			
什么是Shell Shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口(命令解析器),Shell接收用户输入的命令并把它送入到内核去执行,结构如下图 Shell的功能 Shell最重要的 ...