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 ...
随机推荐
- 二分查找(折半查找)C++
二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好,占用系统内存较少: 其缺点是要求待查表为有序表,且插入删除困难. 因此,折半查找方法适用于不经常变动而查找频繁的有序列表. 首先,假设表 ...
- ES6 let和const命令(4)
const声明的常量只在当前代码块有效.如果想设置跨模块的常量,可以采用下面的写法. //constants.js模块 export const A = 1; export const B = 3; ...
- dd 命令详解
作用: dd 是一个Unix和类Unix系统中的命令, 主要功能为转换和赋值文件.在Unix和类Unix系统上, 硬件的设备驱动(如硬盘) 和特殊设备文件(如/dev/zero, /dev/rando ...
- Nginx (二) Nginx的反向代理负载均衡以及日志切割
Nginx是一个高并发,高性能的服务器,可以进行反向代理以及网站的负载均衡.这些功能的运用都在配置文件中,也就是Nginx安装目录下的conf/nginx.conf. nginx.conf 1. 先来 ...
- Illustration of Git branching and merge
网上看到的描述Git工作流程的图片,有些出处忘了保存,仅供学习. 1. One Git Branching Model 出处: http://nvie.com/posts/a-successful-g ...
- 实现全屏轮播,并且轮播div中的文字盒子一直自动垂直居中
效果如下: 直接上代码了: 说明:轮播图基于swiper.js,自行下载.css在最后 <!DOCTYPE html> <html lang="en"> & ...
- jquery通过ajax查询数据动态添加到select
function addSelectData() { //select的id为selectId //清空select中的数据 $("#selectId").empty(); $.a ...
- 盗版SQL Server的性能限制
盗版SQL Server的性能限制 微软的SQL Server产品分为两种卖法1.盒装 :Server+CAL授权方式(SQL2017取消了Server+CAL授权方式,盗版序列号,一般电脑城有卖光盘 ...
- JavaScript的DOM编程--08--复习
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- thinkinginjava学习笔记08_接口
抽象类和抽象方法 抽象方法是指没有具体实现的方法,仅仅有方法的声明和没有方法体:使用abstract关键字定义一个抽象方法:包含抽象方法的类成为抽象类,如果一个类中包含抽象方法则必须使用abstrac ...