hdu 2266 dfs+1258
How Many Equations Can You Find
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 985 Accepted Submission(s):
659
,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.
be sure the length of the string will not exceed 12 and the absolute value of N
will not exceed 999999999999.
number of ways you can find to make the equation.
21 1
1
#include<bits/stdc++.h>
using namespace std;
char num[15],b[105];
int aim,ans,n;
void dfs(int cur,int sum)
{
if(cur==n){
if(sum==aim) ans++;
return;
}
int t=0;
for(int i=cur;i<n;i++){
t=t*10+num[i]-'0'; //其实就是暴力枚举出所有的+-情况
dfs(i+1,sum+t);
if(cur>0) dfs(i+1,sum-t);
}
}
int main()
{
while(cin>>num>>aim/*scanf("%s%d",num,&aim)!=EOF*/){
n=strlen(num);
ans=0;
dfs(0,0);
printf("%d\n",ans);
}
return 0;
}
此类问题类似“决策”,就是每一次/每一个位数对应着几个状态,取/不取或/////
这道题与1258有点类似吧
hdu 2266 dfs+1258的更多相关文章
- hdu 2266 dfs
题意:在数字之间添加运算符号,使得结果等于题目中要求的Sample Input123456789 321 1Sample Output181 这题虽然看起来比较简单,但是之前和差的状态不太好表示,因此 ...
- 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 5143 DFS
分别给出1,2,3,4 a, b, c,d个 问能否组成数个长度不小于3的等差数列. 首先数量存在大于3的可以直接拿掉,那么可以先判是否都是0或大于3的 然后直接DFS就行了,但是还是要注意先判合 ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- 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(DFS)
How Many Equations Can You Find Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- Sum It Up POJ 1564 HDU 杭电1258【DFS】
Problem Description Given a specified total t and a list of n integers, find all distinct sums using ...
- poj 1564 Sum It Up | zoj 1711 | hdu 1548 (dfs + 剪枝 or 判重)
Sum It Up Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Sub ...
- HDU 5877 dfs+ 线段树(或+树状树组)
1.HDU 5877 Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...
随机推荐
- python构造栈结构
栈:是一种先进后出的数据结构:本片文章,我们用python的面向对象来构造这样的数据结构. 栈中的每一个数据除了存储当前的数值外,还存储着当前数值下一个数据的类型(注意不是下一个数据的数值). cla ...
- SNMP学习笔记之iReasoning MIB Browser
0x00 MIB Browser iReasoning MIB浏览器是一个强大和易于使用的工具由iReasoning SNMP API提供支持. MIB浏览器是工程师管理启用SNMP的网络设备和应用程 ...
- Github使用教程(二)------ Github客户端使用方法
在上一篇教程中,我们简单介绍了Github网站的各个部分,相信大家对Github网站也有了一个初步的了解(/(ㄒoㄒ)/~~可是还是不会用怎么办),不要着急,我们今天先讲解一下Github for w ...
- HTML 和 JavaScript 编写简单的 404 界面
编写简单的 404 界面,也可以用来做 500 报错界面,还会飘东西,特别好,蛮漂亮的! <!DOCTYPE html> <html> <head> <met ...
- 20144303石宇森《网络对抗》Web安全基础实践
20144303石宇森<网络对抗>Web安全基础实践 实验后问题回答 SQL注入攻击原理,如何防御: SQL攻击时通过在输入框中输入语句,构造出SQL命令,把这段命令注入到表单中,让后台的 ...
- JAVA I/O(二)文件NIO
一.Unix五种I/O模型 读取和写入文件I/O操作都是调用操作系统提高的接口,对磁盘I/O来说,一般是将数据从磁盘拷贝到内核空间,然后从内核空间拷贝到用户空间.为了减小I/O时间,一般内核空间存在高 ...
- intent bundle的使用
1.什么是bundle Bundle主要用于传递数据:它保存的数据,是以key-value(键值对)的形式存在的.我们经常使用Bundle在Activity之间传递数据,传递的数据可以是boolean ...
- git如何列出分支之间的差异commit
答:使用git log master..diff_master 这样就可以列出在diff_master分支中包含的commit而在master分支中不包含的commit
- HDU 2089 不要62 (数位DP)题解
思路: 详解 数位DP入门题dp[pos][sta],pos代表当前位数是第几位,sta代表当前状态,因为题目中只要不出现64,所以当前状态只分为两种:前一位是6或不是. #include<io ...
- Leading and Trailing(数论/n^k的前三位)题解
Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...