zoukankan      html  css  js  c++  java
  • HDU 4403 A very hard Aoshu problem

    暴力$dfs$。

    先看数据范围,字符串最长只有$15$,也就是说枚举每个字符后面是否放置“$+$”号的复杂度为${2^{15}}$。

    每次枚举到一种情况,看哪些位置能放“$=$”号,每个位置都试一下,然后判断一下是否可行。 最坏复杂度$O({2^{15}}*{15^2})$,事实上是达不到最坏复杂度的。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    
    char s[20];
    int f[20],Ans,len;
    
    bool check()
    {
        LL ans[2]; ans[0]=0; ans[1]=0;
        int g=0; LL num=0;
        for(int i=0;i<len;i++)
        {
            num=num*10+s[i]-'0';
            if(f[i]==0) continue;
            else if(f[i]==1) ans[g]=ans[g]+num, num=0;
            else if(f[i]==2) ans[g]=ans[g]+num, num=0, g=1;
        }
        ans[1]=ans[1]+num;
        if(ans[0]==ans[1]) return 1;
        return 0;
    }
    
    void dfs(int x)
    {
        if(x==len)
        {
            if(f[len-1]==1) return;
            for(int i=0;i<len-1;i++)
            {
                if(f[i]==0)
                {
                    f[i]=2;
                    if(check()) Ans++;
                    f[i]=0;
                }
            }
            return;
        }
        f[x]=0; dfs(x+1);
        f[x]=1; dfs(x+1);
    }
    
    int main()
    {
        while(~scanf("%s",s))
        {
            if(s[0]=='E') break;
            len=strlen(s);
            memset(f,Ans=0,sizeof f);
            dfs(0);
            printf("%d
    ",Ans);
        }
        return 0;
    }
  • 相关阅读:
    正则表达式
    Ajax跨域问题---jsonp
    Ajax
    字符串总结
    js 字符串加密
    jsDate()
    HDU 5430 Reflect
    HDU 5429 Geometric Progression
    HDU 5428 The Factor
    POJ 2485 Highways
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5824454.html
Copyright © 2011-2022 走看看