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, ...
随机推荐
- SpringBoot——定时任务+WebSocket(问题)
开发环境:win7 + idea2018 + jdk 1.8 + springboot 2.x 记一次出现问题,我在项目中先集成了websocket环境,并且测试通过,之后想要模拟实时推送的效果,虽然 ...
- java多线程----拒绝策略
本章介绍线程池的拒绝策略.内容包括:拒绝策略介绍拒绝策略对比和示例 转载请注明出处:http://www.cnblogs.com/skywang12345/p/3512947.html 拒绝策略介绍 ...
- python之路----钻石继承
钻石继承 继承顺序 class A(object): def test(self): print('from A') class B(A): def test(self): print('from B ...
- wireshark捕获表达式之Berkeley Packet Filter (BPF) syntax
就网络抓包来说,绝大部分的情况下,我们都是对特定的ip/端口/协议进行捕获和分析,否则就会有大量的垃圾报文,使得分析和性能低下.大部分的抓包工具都采用BPF语法,具体可参考 http://biot.c ...
- html 5实用特性之data属性
HTML 5之前,我们必须依赖于class和rel属性来存储需要在网站中使用的数据片段,这种做法有时会在网站的外观和实用性之间产生冲突.而HTML 5 Data属性的存在就能很好满足需要. HTML5 ...
- 自定义LisetView
1.ListView listview=findViewById(R.id.listview); 2.public class MyAdapter extends BaseAdapter{ priva ...
- Python3基础 set 自动将重复合并掉 不支持索引
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- PHP Extension
新手搞PHP ,之前用过 PERL, BASH: 所以开始用PHP 写程序上手比较快, 几天之后对PHP 的内部实现机制产生了兴趣,所以自己尝试着写写简单的PHP 扩展,以增加对PHP 的理解. ...
- win10中mount和unmount iso文件
https://www.windowscentral.com/how-mount-or-unmount-iso-images-windows-10 You can also right-click t ...
- excel的C#操作教程
C# Excel Tutorial http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm How to transfer ...