D - A very hard Aoshu problem----(2015 summer training #12(Team_Qualifying))
2015-08-14 15:43
459 查看
D - A very hard Aoshu problem
时限:1000MS 内存:32768KB 64位IO格式:%I64d
& %I64u
问题描述
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.
输入
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".
输出
For each test case , output a integer in a line, indicating the number of equations you can get.
样例输入
样例输出
分析:队友太给力了,直接秒AC。
思路:列举所有的可能性,然后逐一比较。
CODE:
时限:1000MS 内存:32768KB 64位IO格式:%I64d
& %I64u
问题描述
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.
输入
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".
输出
For each test case , output a integer in a line, indicating the number of equations you can get.
样例输入
1212 12345666 1235 END
样例输出
2 2 0
分析:队友太给力了,直接秒AC。
思路:列举所有的可能性,然后逐一比较。
CODE:
#include <bits/stdc++.h> using namespace std; int t[20][20],ans,mid,len; char a[20]; void dfs2(int i,long long data,long long pre){ if (i>len) { if (data==pre) { ans++; return; } } for (int k=i; k<=len; k++) { dfs2(k+1, data+t[i][k], pre); } return; } void dfs1(int i,long long data){ if (i>mid) { dfs2(mid+1,0,data); return; } for (int k=i; k<=mid; k++) { dfs1(k+1, data+t[i][k]); } return; } int main(){ while (scanf("%s",a+1)) { if (!strcmp(a+1,"END")) { break; } len=strlen(a+1); for (int i=1; i<=len; i++) { for (int j=i; j<=len; j++) { t[i][j]=0; for (int k=i; k<=j; k++) { t[i][j]=t[i][j]*10+(a[k]-'0'); } cout<<t[i][j]<<endl; } } ans=0; for (mid=1; mid<len; mid++) { dfs1(1, 0); } printf("%d\n",ans); } return 0; }
相关文章推荐
- 2015新型程序设计语言:Braise语言详细介绍(有图文)
- Openerp几个Email问题处理方法
- mDNS之airplay实现及问题总结
- [LeetCode] Paint House
- Extmail maildrop错误
- ava I/O 操作及优化建议 NIO AIO
- 导出gmail邮件
- 谈话ZooKeeper(一个)分析ZooKeeper的Quorums机制--预防Split-Brain问题
- J - Flyer------(2015 summer training #11)
- Factorial Trailing Zeroes
- F - Stone-----(2015 summer training #11)
- HDU4300-Clairewd’s message-KMP
- E - Theme Section-----(2015 summer training #11)
- D - Cut the Cake----(2015 summer training #11)
- error: linker command failed with exit code 1 (use -v to see invocation)
- J - A Bit Fun-----(2015 summer training #9)
- SGU183 Painting the balls(DP+优化)
- D - Minimum palindrome----(2015 summer training #9)
- C - We Love MOE Girls-----(2015 summer training #9)
- B - Median-----(2015 summer training #8(Qualifying))