A very hard Aoshu problem

                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
Aoshu 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.

 
Input
There 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".
 
Output
For each test case , output a integer in a line, indicating the number of equations you can get.
 
Sample Input
1212
12345666
1235
END
 
Sample Output
2
2
0
 
Source
题解:枚举等号
  等号两边暴力dfs
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define memfy(a) memset(a,-1,sizeof(a))
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define mod 1000000007
#define maxn 106
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
int n,m,ans,fsum;
vector<int >G[];
char a[];
void dfs1(int x,int right,int sum,int last)
{
if(x==right)
{
if(!last)
G[].push_back(sum+last);
return ;
}
dfs1(x+,right,sum+last*+a[x],);///f
dfs1(x+,right,sum,last*+a[x]);
}
void dfs2(int x,int right,int sum,int last)
{
if(x==right)
{if(!last)
G[].push_back(sum+last);
return ;
}
dfs2(x+,right,sum+last*+a[x],);///f
dfs2(x+,right,sum,last*+a[x]);
}
int main()
{ while(scanf("%s",a)!=EOF)
{
ans=;
if(strcmp(a,"END")==)
break;
n=strlen(a);
FOR(i,,n-)a[i]=a[i]-'';
FOR(i,,n-)
{
G[].clear();G[].clear();
if(i==) G[].push_back(a[]);
else dfs1(,i,,);
if(i==n-) G[].push_back(a[i]);
else dfs2(i,n,,);
for(int j=;j<G[].size();j++)
for(int k=;k<G[].size();k++)
{
if(G[][j]==G[][k])ans++;
}
}
cout<<ans<<endl;
///getchar();
}
return ;
}

代码

HDU4403 A very hard Aoshu problem DFS的更多相关文章

  1. HDU 4403 A very hard Aoshu problem(DFS)

    A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...

  2. A very hard Aoshu problem(dfs或者数位)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4403 A very hard Aoshu problem Time Limit: 2000/1000 ...

  3. 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 ...

  4. 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 ...

  5. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  6. HDU 4403 A very hard Aoshu problem(dfs爆搜)

    http://acm.hdu.edu.cn/showproblem.php?pid=4403 题意: 给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子. 思路: 数据量比 ...

  7. 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 ...

  8. CDOJ 483 Data Structure Problem DFS

    Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...

  9. A very hard Aoshu problem

    A very hard Aoshu proble Problem Description Aoshu is very popular among primary school students. It ...

随机推荐

  1. Cloudera’s Distribution Including Apache Hadoop(CDH)安装过程

    文档地址:https://www.cloudera.com/documentation.html                 https://www.cloudera.com/documentat ...

  2. 如何HTML标签和JS中设置CSS3 var变量

    一.HTML标签中设置CSS变量 如下: <div style="--color: #cd0000;"> <img src="mm.jpg" ...

  3. Codeforces Beta Round #93 (Div. 2 Only) (Virtual participation)

    A 相邻点对距离和*k B (Σ(v/2))/2 C 一直想不到"最优"是怎么体现的,发现y2=y1*(t1-t0)/(t0-t2),就写了1e6的枚举,然而又一些特殊情况没考虑到 ...

  4. thinkphp3.2使用PHPQrcode实现二维码

    Thinkphp中没有二维码相关的生成库,百度有不少工具和库 这里就实例一下通过think3.2搭配phpqrcode来完成生成二维码的功能. 至于phpQrcode库文件 百度很容易找到这里也给大家 ...

  5. sed输出指定行

    and line ,8p to line ,8p -e 20p - and line -n:取消默认输出.注意:sed命令会默认把输入行打印到屏幕上,所以如果想精准的控制输出,就需要-n. -e:进行 ...

  6. assert.ok()详解

    assert.ok(value[, message]) 测试 value 是否为真值.它等同于 assert.equal(!!value, true, message). 如果 value 不是真值, ...

  7. 10.Spring Bean的生命周期

    Spring IOC容器可以管理Bean的生命周期,允许在Bean声明周期的特定点执行定制的任务. Spring IOC容器对Bean的生命周期进行管理的过程. 1.通过构造器或工厂方法创建Bean实 ...

  8. 集训第四周(高效算法设计)O题 (构造题)

    A permutation on the integers from 1 to n is, simply put, a particular rearrangement of these intege ...

  9. HDU 5420 Victor and Proposition

    Victor and Proposition Time Limit: 6000ms Memory Limit: 524288KB This problem will be judged on HDU. ...

  10. 九度oj 题目1072:有多少不同的面值组合?(set集合)

    题目1072:有多少不同的面值组合? 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3627 解决:1852 题目描述: 某人有8角的邮票5张,1元的邮票4张,1元8角的邮票6张,用这些邮 ...