HDU 2266 How Many Equations Can You Find(模拟,深搜)

题目

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

//我要做深搜题目拉
//实际上还是模拟

#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int ans;
char a[20];
__int64 n;
int fuhao[20];
int len;
__int64 cal()
{
    int fh=0;
    __int64 num=0,tmp=0;
    tmp=a[0]-‘0‘;
    for(int i=1;i<len;i++){
        if(fuhao[i-1]==1){
            if(fh==1)num+=tmp;
            else if(fh==2)num-=tmp;
            else if(fh==0)num=tmp;
            tmp=0;
            fh=1;
        }
        else if(fuhao[i-1]==2){
            if(fh==1)num+=tmp;
            else if(fh==2)num-=tmp;
            else if(fh==0)num=tmp;
            tmp=0;
            fh=2;
        }
        tmp=tmp*10+a[i]-‘0‘;
    }
    if(fh==1)num+=tmp;
    else if(fh==2)num-=tmp;
    else num=tmp;
    return num;
}
void dfs(int st)
{
    if(st==len-1){//符号比数少一位
        if(cal()==n)ans++;
        return;
    }
    fuhao[st]=0;
    dfs(st+1);
    fuhao[st]=1;
    dfs(st+1);
    fuhao[st]=2;
    dfs(st+1);
}

int main()
{
    while(scanf("%s%I64d",a,&n)!=EOF)
    {
        memset(fuhao,0,sizeof(fuhao));
        len=strlen(a);
        ans=0;
        dfs(0);
        printf("%d\n",ans);
    }
    return 0;
}

时间: 2024-08-08 05:36:45

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

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

http://acm.hdu.edu.cn/showproblem.php?pid=2266 给一个字符串和一个数n,在字符串中间可以插入+或者 -,问有多少种等于n的情况. 要注意任意两个数之间都可以插入也可以不插入,注意枚举完所有情况. #include <cstdio> #include <cstring> char s[15]; int n,l,cnt; void dfs(int k,int sum) { if(k==l) { if(sum==n) cnt++; retur

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 & %I64u Description 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 char

hdu 2266 How Many Equations Can You Find

How Many Equations Can You Find Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 644    Accepted Submission(s): 424 Problem Description Now give you an string which only contains 0, 1 ,2 ,3 ,4 ,

HDU 4028 The time of a day STL 模拟题

暴力出奇迹.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define ll __int64 #define N 42 ll n,m,ans;

HDU 4930 Fighting the Landlords(扯淡模拟题)

Fighting the Landlords 大意: 斗地主....   分别给出两把手牌,肯定都合法.每张牌大小顺序是Y (i.e. colored Joker) > X (i.e. Black & White Joker) > 2 > A (Ace) > K (King) > Q (Queen) > J (Jack) > T (10) > 9 > 8 > 7 > 6 > 5 > 4 > 3. 给你8种组合:1.

HDU 1048 What Is Your Grade? (简单模拟)

 What Is Your Grade? Problem Description "Point, point, life of student!" This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in

【深搜加剪枝五】HDU 1010 Tempter of the Bone

Tempter of the BoneTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 64326    Accepted Submission(s): 17567 Problem Description The doggie found a bone in an ancient maze, which fascinated him a l

深搜基础题目 杭电 HDU 1241

HDU 1241 是深搜算法的入门题目,递归实现. 原题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1241 代码仅供参考,c++实现: #include <iostream> using namespace std; char land[150][150]; int p,q; void dfs(int x,int y){ land[x][y] = '*'; if(land[x-1][y]!= '@' && land[x+1]

hdu 1175 连连看 (深搜)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 题目大意:如果某两个相同的棋子,可以通过一条线连起来(这条线不能经过其它棋子)这样的两个棋子可以消掉.还有一个要注意的地方的就是转弯.转弯的次数不超过两次,这两个棋子才可以在棋盘上消去~ 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 int