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 ...
随机推荐
- Excel——使用VLOOKUP函数关联跨工作薄数据
实验环境 有两个工作簿,一个是<花名册>,另一个是<入离职表>,<花名册>上有所有员工的详细信息,包括员工的姓名.部门.出生日期等,<入离职表>上有离职 ...
- FMDB官方使用文档-GCD的使用-提高性能(翻译)
FMDB官方使用文档-GCD的使用-提高性能(翻译) 发布于:2013-08-19 10:01阅读数:13395 由于FMDB是建立在SQLite的之上的,所以你至少也该把这篇文章从头到尾读一遍.与此 ...
- 关于hash
http://rapheal.iteye.com/blog/1142955 关于javascript hash
- 一颗 45nm CPU的制造过程
沙子 :硅是地壳内第二丰富的元素,而脱氧后的沙子(尤其是石英)最多包含25%的硅元素,以二氧化硅(SiO2)的形式存在,这也是半导体制造产业的基础. 硅熔炼: 12英寸/300毫米晶圆级,下同.通过多 ...
- Static, Shared Dynamic and Loadable Linux Libraries
转载:http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html Why libraries are used: Th ...
- 编译不通过:提示XXXX不是类或命名空间名 的解决办法
手动写了一个类,需要引入预编译头stdafx.h.结果编译时提示XXXX不是类或命名空间名. 处理方法:将#include "stdafx.h"放在最前面.
- WIN8共享文件 详细设置
原文地址:http://jingyan.baidu.com/article/75ab0bcbff4274d6864db2f5.html win8共享文件设置 详细教程 | 浏览:6987 | 更新:2 ...
- Razor Generator 将cshtml自动生成对应的CS文件
- Hdu3812-Sea Sky(深搜+剪枝)
Sea and Sky are the most favorite things of iSea, even when he was a small child. Suzi once wrote: ...
- 【POJ1581】A Contesting Decision(简单模拟)
没有什么弯路,直接模拟即可.水题. #include <iostream> #include <cstring> #include <cstdlib> #inclu ...