HDU4403 A very hard Aoshu problem DFS
A very hard Aoshu problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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.
12345666
1235
END
2
0
//
#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的更多相关文章
- HDU 4403 A very hard Aoshu problem(DFS)
A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...
- A very hard Aoshu problem(dfs或者数位)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4403 A very hard Aoshu problem Time Limit: 2000/1000 ...
- 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 ...
随机推荐
- vue解决IOS10低版本白屏问题
一.方案一 在build文件的webpack.prod.conf.js文件添加以下代码 new UglifyJsPlugin({ uglifyOptions: { compress: { warnin ...
- Beam Search
Q: 什么是Beam Search? 它在NLP中的什么场景里会⽤到? 传统的广度优先策略能够找到最优的路径,但是在搜索空间非常大的情况下,内存占用是指数级增长,很容易造成内存溢出,因此提出了beam ...
- LeetCode1-5
Leetcode1: Given an array of integers, return indices of the two numbers such that they add up to a ...
- [C语言]输入一行整数,用空格分开,回车结束。
在屏幕一行中的字符会保留在缓冲区,例如 1 2 3 4 5 6 ; i < n; i++) { scanf("%d",&cur); array[i] = cur; c ...
- 关于ie8下disabled属性:字体颜色问题
在ie8下,input/textarea输入框如果使用disabled属性,字体的颜色会变灰,这时我们可以使用另一种方法实现它. 不使用disabled,用readonly代替: input[read ...
- java字符串利用正则表达式分割
平时用到,整理的,总感觉缺点什么: private String getKeywordByContent(String content) { StringBuffer sbAllKwyword = n ...
- BNUOJ 26228 Juggler
Juggler Time Limit: 3000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 42 ...
- 【springmvc】传值的几种方式&&postman接口测试
最近在用postman测试postman接口,对于springmvc传值这一块,测试了几种常用方式,总结一下.对于postman这个工具的使用也增加了了解.postman测试很棒,有了工具,测试接口, ...
- 【HDOJ3341】Lost's revenge(AC自动机,DP)
题意:给出一个n个模式串,一个目标串,问把目标串重新排位最多能产生多少个模式串,可以重叠且所有串只包含A C G T. n<=10,len[i]<=10 len(s)<=40 Cas ...
- Android 网络连接状态的监控
有些应用需要连接网络,例如更新后台服务,刷新数据等,最通常的做法是定期联网,直接使用网上资源.缓存数据或执行一个下载任务来更新数据. 但是如果终端设备没有连接网络,或者网速较慢,就没必要执行这些任务. ...