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.

InputEach 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.OutputThe 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 题目大意就是 在一个在来两个数字之间添加+ — 或者不做处理 使他可以得到后一个数,并记录次数就好了
思路:DFS遍历每一种情况
#include<iostream>
#include<string >
using namespace std;
string a;
typedef long long ll;
ll n,ans;
void dfs(int row,int sum){
if(row==a.size())
{
if(sum==n)
ans++;
return ;
} ll t=;
for(int i=row;i<a.size();i++)
{
t=t*+a[i]-'';
dfs(i+,sum+t);
if(row==) continue ; //因为当row==0时 sum=0,如过加减号的话相当于在第一个数前边加负号,所以要跳过
     dfs(i+,sum-t);
}
} int main()
{
while(cin>>a>>n){
ans=;
dfs(,);
cout<<ans<<endl;
}
return ;
}

B - How Many Equations Can You Find dfs的更多相关文章

  1. 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 [从零 ...

  2. 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 ...

  3. How Many Equations Can You Find(dfs)

    How Many Equations Can You Find Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  4. ZOJ1204——Additive equations(DFS)

    Additive equations Description We all understand that an integer set is a collection of distinct int ...

  5. hdu - 2266 How Many Equations Can You Find (简单dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=2266 给一个字符串和一个数n,在字符串中间可以插入+或者 -,问有多少种等于n的情况. 要注意任意两个数之间都可 ...

  6. HDU5937 Equation(DFS + 剪枝)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5937 Description Little Ruins is a studious boy, ...

  7. zoj 1204 Additive equations

    ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...

  8. HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))

    Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. HDU 4403 A very hard Aoshu problem(DFS)

    A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...

随机推荐

  1. Contest 158

    2019-10-14 15:30:38 总体感受:这次依然很快搞定了前三题,最后一题乍看之下还是比较简单的,但是出奇多的corner case让我非常苦恼,这也让我意识到要想真正征服最后一题,还有一个 ...

  2. 滑动窗口-Substring Search Problem

    2018-07-18 11:19:19 一.Minimum Window Substring 问题描述: 问题求解: public String minWindow(String s, String ...

  3. 教你如何利用threejs对3D模型皮肤进行DIY

    一步一步教你如何利用threejs加载gltf模型来实现DIY换肤功能. 模型准备 模型制作 模型可以通过网上下载,也可以自己通过c4d.maya.blender等模型制作软件得到.这里就不叙述有关模 ...

  4. Mysql失败,异常pymysql.err.InternalError: (1366, "Incorrect string value: '\\xF0\\x9D\\x90\\xBF;......

    问题描述: 插入Mysql时失败了,python代码报如下异常: pymysql.err.InternalError: (1366, "Incorrect string value: '\\ ...

  5. 解决使用requests_html模块,html.render()下载chromium报错、速度慢问题

    来源:https://www.cnblogs.com/xiaoaiyiwan/p/10776493.html 稍作修改 1.第一步,代码如下: from requests_html import HT ...

  6. PySpark初级教程——第一步大数据分析(附代码实现)

    概述 数据正以前所未有的速度与日俱增 如何存储.处理和使用这些数据来进行机器学习?spark正可以应对这些问题 了解Spark是什么,它是如何工作的,以及涉及的不同组件是什么 简介 我们正在以前所未有 ...

  7. CSS3过渡结束监听事件,清除/修改表单元素的一些默认样式

    document.querySelector('div').addEventListener('transitionEnd',function(){ console.log('过度结束') }) 如果 ...

  8. coding++:Spring Boot全局事务解释及使用(一)

    Spring 事务的入口: TxAdviceBeanDefinitionParser 解释 <tx:advice/> 这里将解析tx的配置. @Override protected Cla ...

  9. 【WPF学习】第六十一章 组织模板资源

    为表达全国各族人民对抗击新冠肺炎疫情斗争牺牲烈士和逝世同胞的深切哀悼,国务院今天发布公告,决定2020年4月4日举行全国性哀悼活动. 当使用控件模板时,需要决定如何更广泛地共享模板,以及是否希望自动地 ...

  10. 关于 IDEA 启动 springboot 项目异常 - Disconnected from the target VM, address: '127.0.0.1:59770', transport: 'socket'

    关于 IDEA 启动 springboot 项目异常 - Disconnected from the target VM, address: '127.0.0.1:59770', transport: ...