HDU 2266 How Many Equations Can You Find(DFS)
How Many Equations Can You Find
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Now give you an string which only contains 0, 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9.You are asked to add the sign ‘+’ or ’-’ between the characters. Just like give you a string “12345”, you can work out a string “123+4-5”. Now give you an integer N, please tell me how many ways can you find to make the result of the string equal to N .You can only choose at most one sign between two adjacent characters.
Input
Each case contains a string s and a number N . You may be sure the length of the string will not exceed 12 and the absolute value of N will not exceed 999999999999.
Output
The output contains one line for each data set : the number of ways you can find to make the equation.
Sample Input
123456789 3 21 1
Sample Output
18 1
简单翻译:
给你两个数n,m.你需要在n的中间填上加号或减号,或者不填。让n这个部分的值等于m。问有多少种方案。
举个例子:n=12345.
你可以操作它,使它变成这样 123+4-5=122。
解题思路:
dfs,考虑已经处理的数字的个数和当前这部分的值,处理到终点时,如果等于m,结果+1.
代码:
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
char String[];
LL Equation;
int Length,Answer;
void Search_For_Answer(int Now_Position,LL Now_Value)
{
if(Now_Position>=Length)
{
if(Now_Value==Equation) Answer++;
return;
}
LL Temp_Value=;
for(int i=;i<=Length-Now_Position;i++)
{
Temp_Value=Temp_Value*+String[i-+Now_Position]-'';
Search_For_Answer(Now_Position+i,Now_Value+Temp_Value);
if(Now_Position)
Search_For_Answer(Now_Position+i,Now_Value-Temp_Value);
}
}
int main()
{
while(scanf("%s%lld",String,&Equation)!=EOF)
{
Answer=;
Length=strlen(String);
Search_For_Answer(,);
printf("%d\n",Answer);
}
return ;
}
HDU 2266 How Many Equations Can You Find(DFS)的更多相关文章
- HDOJ(HDU).2266 How Many Equations Can You Find (DFS)
HDOJ(HDU).2266 How Many Equations Can You Find (DFS) [从零开始DFS(9)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零 ...
- hdu - 2266 How Many Equations Can You Find (简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2266 给一个字符串和一个数n,在字符串中间可以插入+或者 -,问有多少种等于n的情况. 要注意任意两个数之间都可 ...
- HDU 2266 How Many Equations Can You Find(模拟,深搜)
题目 这是传说中的深搜吗....不确定,,,,貌似更加像是模拟,,,, //我要做深搜题目拉 //实际上还是模拟 #include<iostream> #include<string ...
- hdu 2266 dfs+1258
How Many Equations Can You Find Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- 【HDOJ】2266 How Many Equations Can You Find
简单DFS. #include <cstdio> #include <cstring> #define MAXN 15 char str[MAXN]; __int64 x; i ...
- hdu 2266 dfs
题意:在数字之间添加运算符号,使得结果等于题目中要求的Sample Input123456789 321 1Sample Output181 这题虽然看起来比较简单,但是之前和差的状态不太好表示,因此 ...
- HDU 5416 CRB and Tree(前缀思想+DFS)
CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 2181 哈密顿绕行世界问题(经典DFS+回溯)
哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- How Many Equations Can You Find(dfs)
How Many Equations Can You Find Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
随机推荐
- ActiveX in QT
http://doc.qt.io/qt-4.8/activeqt.htmlhttp://doc.qt.io/qt-5/activeqt-index.html
- 《Programming WPF》翻译 第8章 4.关键帧动画
原文:<Programming WPF>翻译 第8章 4.关键帧动画 到目前为止,我们只看到简单的点到点的动画.我们使用了To和From属性或者By属性来设计动画--相对于当前的属性值.这 ...
- [科普]MinGW vs MinGW-W64及其它
转载:http://tieba.baidu.com/p/3186234212?pid=54372018139&cid=#54372018139 这里也转一下吧. 部分参照备忘录原文: bitb ...
- Check whether a given Binary Tree is Complete or not 解答
Question A complete binary tree is a binary tree in which every level, except possibly the last, is ...
- IOS开发错误提示原因集合-----长期更新
"[__NSCFConstantString size]: unrecognized selector sent to instance." =>将NSString类型的参数 ...
- web应用的发布
将web应用打包成.war类型的...因为将其发布到服务器时,其自动解压...非常方便
- qt 操作excel表格
自己编写的一个Qt C++类,用于操作excel表格,在Qt中操作excel需在.pro中增加CONFIG+=qaxcontainer配置. 1.打开Excel:objExcel = new QAx ...
- 2. QT窗体间值的传递
一.主窗体与子窗体传参 方法有很多,这里介绍一种通过重载子窗体的构造函数实现主窗体参数传入到子窗体,并通过QT信号和槽的机制实现子窗口到主窗口值的传递. 主和子窗体的设置如下: 主要实现功能为: 1 ...
- html基本基础
一 HTML5是用来做什么的? PSD2HTML 信息 信息差(信息不对称) 二 html文件新建流程: 新建文本文件 网页文件后缀 .html 修改编码:ANSI格式,UTF-8无BOM格式==== ...
- .net对象转Datable
public static DataTable GetDataTable<T>( IEnumerable<T> list,string tableName) { DataTab ...