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. secureCRT 破解

    转自:http://www.cnblogs.com/qingtingzhe/articles/5008902.html

  2. android-async-http框架库使用基础

    开源项目链接 android-async-http仓库:git clone https://github.com/loopj/android-async-http android-async-http ...

  3. 字符与数字的转换:sprintf和sscanf

    目录 字符与数字的转换:sprintf和sscanf 简单介绍 实例 运行结果 字符与数字的转换:sprintf和sscanf 简单介绍 sprintf和sscanf都是stdio.h头文件中的函数, ...

  4. react初探索--react + react-router + ant-design 后台管理系统配置

    首先确认安装了node环境,Node >= 6. 如果对react 及 ant-design 一无所知,建议去阅读下api文档,react 可以在 codePen 在线练习. react Api ...

  5. linux与linux之间共享目录

    1.安装必要的包 nfs-utils           rpcbind (nfs是基于sun公司的rpc通信实现的,所以要装rpcbind) 这2包,在服务端和客户端都需要安装,并启动服务. 启动 ...

  6. xtrbackup备份mysql

    mysqldump备份方式是采用逻辑备份,但是它最大的缺陷就是备份和恢复速度慢对于一个小于50G的数据库而言,这个速度还是能接受的,但如果数据库非常大,那再使用mysqldump备份就不太适合了. x ...

  7. 使用Hashids来保护你的数据库主键

    为什么要保护数据库主键? 数据库主键一般是有序自增主键,极易被爬虫抓取数据,作为应用开发者,这是不应该的,你辛辛苦苦收集的数据转眼之间被其他人给抓取了,是不是很大的损失? Hashids的介绍 gen ...

  8. Python接口测试之unittest框架(五)

    Test-driven development(TDD)开发模式在今天已经不是什么新奇的事了,它的开发思维是在开发一个产品功能的时候,先 编写好该功能的测试代码,在编写开发比如,比如要写二个数相除的函 ...

  9. NYOJ-768移位密码,最简单的代替密码;

    移位密码 时间限制:1000 ms  |  内存限制:65535 KB 难度:0 ->   Link   <- 还有1个半小时考信息安全导论,昨晚心血来潮在oj上看到这几个题,简直就是水啊 ...

  10. CSU 1214 找最大异或值

    题目大意: 给定一堆数,从中找2个数异或得到的最大值 直接暴力会超时,我们要考虑对于每一个数去匹配找到异或的最大值,我们希望2进制越前面的数尽可能都为1 所以我们用 0-1 字典树保存这些数,因为一个 ...