B - How Many Equations Can You Find dfs
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的更多相关文章
- 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)
How Many Equations Can You Find Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- How Many Equations Can You Find(dfs)
How Many Equations Can You Find Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- ZOJ1204——Additive equations(DFS)
Additive equations Description We all understand that an integer set is a collection of distinct int ...
- hdu - 2266 How Many Equations Can You Find (简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2266 给一个字符串和一个数n,在字符串中间可以插入+或者 -,问有多少种等于n的情况. 要注意任意两个数之间都可 ...
- HDU5937 Equation(DFS + 剪枝)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5937 Description Little Ruins is a studious boy, ...
- zoj 1204 Additive equations
ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 4403 A very hard Aoshu problem(DFS)
A very hard Aoshu problem Problem Description Aoshu is very popular among primary school students. I ...
随机推荐
- leetcode签到 892. 三维形体的表面积
题目 三维形体的表面积 在 N * N 的网格上,我们放置一些 1 * 1 * 1 的立方体. 每个值 v = grid[i][j] 表示 v 个正方体叠放在对应单元格 (i, j) 上. 请你返回最 ...
- Trie树的简单实现
import java.util.ArrayList; import java.util.TreeMap; import util.FileOperation; public class Trie { ...
- Redis 缓存更新一致性
当执行写操作后,需要保证从缓存读取到的数据与数据库中持久化的数据是一致的,因此需要对缓存进行更新. 因为涉及到数据库和缓存两步操作,难以保证更新的原子性. 在设计更新策略时,我们需要考虑多个方面的问题 ...
- Building Applications with Force.com and VisualForce(Dev401)( 八):Designing Applications for Multiple users:Managing your users' experience II
Dev 401-008: Design Applications for Multiple Users' Experience Part 2Universal Containers Scenario1 ...
- mongodb_2
一.游标 在mongodb中,底层使用js引擎进行各种操作,所以我们在命令行窗口,可直接执行js代码. #使用for循环,插入1000条数据. > for (var i=0;i<1000; ...
- 最简单的 TensorFlow 代码,TensorFlow Hello World 。
# -*- coding:utf-8 -*- from __future__ import print_function ''' HelloWorld example using TensorFlow ...
- Codeforces 杂题集 2.0
记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序 1326D2 - Prefix-Suffix Palindrome (Hard version) ...
- 解决Python pip安装第三方包慢的问题
解决Python pip安装第三方包慢的问题 主要是修改源,国内的源有几个 阿里云 http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi ...
- 原生js焦点轮播图的实现
继续学习打卡,武汉加油,逆战必胜!今日咱们主要探讨一下原生js写轮播图的问题, 简单解析一下思路: 1,首先写好css样式问题 2,考虑全局变量:自动播放的定时器,以及记录图片位置的角标Index 2 ...
- D 楼房重建
时间限制 : - MS 空间限制 : - KB 评测说明 : 1s,256m 问题描述 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊 ...