HDU4403-A very hard Aoshu problem
来源:互联网 发布:雷欧奥特曼mac 编辑:程序博客网 时间:2024/06/07 10:53
A very hard Aoshu problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1520 Accepted Submission(s): 1041
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.
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
1212123456661235END
Sample Output
220
Source
2012 ACM/ICPC Asia Regional Jinhua Online
解题思路:先预处理出每一段的数值,在数值中间放登号,然后dfs
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <set>#include <map>using namespace std;#define LL long longint ans;int x[20][20];char ch[20];int len;void init(){ memset(x,0,sizeof x); for(int i=0;i<len;i++) { for(int j=i;j<len;j++) { for(int k=i;k<=j;k++) x[i][j]=x[i][j]*10+(ch[k]-'0'); } }}void dfs(int k,int pos,int sum1,int sum2){ if(pos>=len) { if(sum1==sum2) { ans++;return ; } } if(pos<=k) { for(int i=pos;i<=k;i++) dfs(k,i+1,sum1+x[pos][i],sum2); } else { for(int i=pos;i<len;i++) dfs(k,i+1,sum1,sum2+x[pos][i]); }}int main(){ while(~scanf("%s",ch)&&(ch[0]!='E')) { ans=0; len=strlen(ch); init(); for(int i=0;i<len-1;i++) dfs(i,0,0,0); printf("%d\n",ans); } return 0;}
0 0
- HDU4403-A very hard Aoshu problem
- HDU4403:A very hard Aoshu problem(DFS暴搜)
- A very hard Aoshu problem
- A very hard Aoshu problem
- HDU 4403 A very hard Aoshu problem
- hdu 4403 A very hard Aoshu problem
- HDU:4403 A very hard Aoshu problem
- HDU 4403 A very hard Aoshu problem
- HDU 4403 A very hard Aoshu problem
- HDU 4403(A very hard Aoshu problem)
- HDU 4403 A very hard Aoshu problem
- A very hard Aoshu problem(HDU4402)
- hdu 4403 A very hard Aoshu problem
- hdu 4403 A very hard Aoshu problem
- HDU 4403A very hard Aoshu problem
- A very hard Aoshu problem HDU-4403
- hdu 4403 A very hard Aoshu problem
- hdu4403A very hard Aoshu problem
- 函数式编程初探
- 利用栈实现中缀表达式转后缀表达式
- Python之import
- 蓝桥杯 算法训练 出现次数最多的整数(水)
- 2017年JavaScript编码规范技能图谱-全栈工程师熊盼
- HDU4403-A very hard Aoshu problem
- 华为机试在线训练-牛客网(7)字符个数统计
- Java 脚本支持
- HNOI(湖南省选试题)——永无乡
- linux下IDA安装使用
- n-1位数
- small_arts:球球大作战刷(秒点/代点)棒棒糖网站地址
- 《unix网络编程》中readline函数改进版
- 聊聊代码提交那些事