题目

这是传说中的深搜吗。。。。不确定,,,,貌似更加像是模拟,,,,

//我要做深搜题目拉
//实际上还是模拟 #include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int ans;
char a[];
__int64 n;
int fuhao[];
int len;
__int64 cal()
{
int fh=;
__int64 num=,tmp=;
tmp=a[]-'';
for(int i=;i<len;i++){
if(fuhao[i-]==){
if(fh==)num+=tmp;
else if(fh==)num-=tmp;
else if(fh==)num=tmp;
tmp=;
fh=;
}
else if(fuhao[i-]==){
if(fh==)num+=tmp;
else if(fh==)num-=tmp;
else if(fh==)num=tmp;
tmp=;
fh=;
}
tmp=tmp*+a[i]-'';
}
if(fh==)num+=tmp;
else if(fh==)num-=tmp;
else num=tmp;
return num;
}
void dfs(int st)
{
if(st==len-){//符号比数少一位
if(cal()==n)ans++;
return;
}
fuhao[st]=;
dfs(st+);
fuhao[st]=;
dfs(st+);
fuhao[st]=;
dfs(st+);
} int main()
{
while(scanf("%s%I64d",a,&n)!=EOF)
{
memset(fuhao,,sizeof(fuhao));
len=strlen(a);
ans=;
dfs();
printf("%d\n",ans);
}
return ;
}

HDU 2266 How Many Equations Can You Find(模拟,深搜)的更多相关文章

  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 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

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

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

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

  5. hdu 2266 dfs+1258

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

  6. hdu 5648 DZY Loves Math 组合数+深搜(子集法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5648 题意:给定n,m(1<= n,m <= 15,000),求Σgcd(i|j,i&am ...

  7. 深搜基础题目 杭电 HDU 1241

    HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #incl ...

  8. (深搜)Oil Deposits -- hdu -- 1241

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  9. hdu 1518 Square(深搜+剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! ...

随机推荐

  1. AutoCAD 2014:安装时发生allied product not found错误

    有个朋友在安装AutoCAD 2014时不慎误删了一个文件夹,结果导致安装AutoCAD时总是跳出”allied product not found”的错误. Google搜了下,解决方案如下: 1. ...

  2. UVa 263 - Number Chains

    题目:给你一个数字n0.将它的每一个位的数字按递增排序生成数a,按递减排序生成数b, 新的数字为n1 = a-b,下次依照相同方法计算n1,知道出现循环,问计算了多少次. 分析:数论.模拟.直接模拟计 ...

  3. 《CS:APP》 chapter 9 Vitrual Memory 笔记

    Vitrual Memory In order to manage memory more efficiently and with fewer errors, modern systems prov ...

  4. hibernate4中oracle,sqlserver,mysql数据库的sql方言配置(SQL Dialects)

    hibernate4中oracle,mysql,sqlserver数据库的sql方言配置(SQL Dialects) 数据库类型 Hibernate sql方言 DB2 org.hibernate.d ...

  5. WPF学习笔记——设置ListBox选中项的背景颜色

    ListBox的选中项,在我这个WIN7里面,是亮蓝色,颜色是如此之浓厚,差不多遮盖了前景的字体! 太不协调了.可是怎么设置呢?设置触发器,又是IsMouseOver,又是IsFocused,在谷歌里 ...

  6. luogu1514 引水入城

    题目大意 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个NN 行\times M×M 列的矩形,如上图所示,其中每个格子都代表一座城市,每座城市 ...

  7. C# datagridview 删除行(转 学会、放弃博客)

    原文引入:http://zhangyanyansy.blog.163.com/blog/static/13530509720106171252978/ datagridview 删除行 2010-07 ...

  8. Python开发利器PyCharm 2.7附注册码

    PyCharm 2.7 下载 http://download.jetbrains.com/python/pycharm-2.7.2.exe 激活注册 user name:EMBRACE key: 14 ...

  9. C语言实现字符串拼接

    #include <stdio.h>#include <stdlib.h>#include <string.h> char* str_contact(const c ...

  10. [Apple开发者帐户帮助]三、创建证书(5)创建WatchKit服务证书

    WatchKit服务证书允许您使用Apple推送通知(APN)将更新推送到Apple Watch上的复杂功能. 所需角色:帐户持有人或管理员. 在证书,标识符和配置文件中,从左侧的弹出菜单中选择iOS ...