• hdu 4403 枚举


    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    using namespace std;
    
    const int maxe = 50000;
    const int maxn = 17;
    const int INF  = 0x3f3f3f;
    
    vector<int> l[maxn];
    vector<int> r[maxn];
    
    char s[maxn];
    
    inline int cal(int a,int b){
        int ret = 0;
        for(int i=a;i<=b;i++)
            ret = ret*10 + s[i] - '0';
        return ret;
    }
    int main()
    {
        //freopen("E:\acm\input.txt","r",stdin);
    
        while(scanf("%s",s+1) && s[1]!='E'){
            int N = strlen(s+1);
            for(int i=0;i<=N;i++)  l[i].clear();
            for(int i=0;i<=N;i++)  r[i].clear();
    
            l[1].push_back(s[1]-'0');
            for(int i=2;i<=N-1;i++){
    
                for(int j=0;j<i;j++){
                    int num = cal(j+1,i);
                    if(j == 0){
                        l[i].push_back(num);
                        continue;
                    }
                    for(int k=0;k<l[j].size();k++){
                        l[i].push_back(l[j][k] + num);
                    }
                 }
                sort(l[i].begin(),l[i].end());
            }
            r[N].push_back(s[N]-'0');
            for(int i=N-1;i>=2;i--){
                for(int j=N+1;j>i;j--){
                    int num = cal(i,j-1);
                    if(j == N+1){
                        r[i].push_back(num);
                        continue;
                    }
                    for(int k=0;k<r[j].size();k++){
                        r[i].push_back(r[j][k] + num);
                    }
                 }
                sort(r[i].begin(),r[i].end());
            }
    
            int ans = 0;
            for(int i=1;i<=N-1;i++){
                for(int j=0;j<l[i].size();j++){
                    for(int k=0;k<r[i+1].size();k++){
                        if(l[i][j] == r[i+1][k]){
                            ans++;
                        }
                    }
                }
            }
            printf("%d
    ",ans);
        }
    }
    View Code
  • 相关阅读:
    [转]人生哲理小故事
    取PE文件OriginalFilename解析VERSION资源
    [转]COM对象创建外部机制
    读书的几个步骤
    zoj 2412 Farm Irrigation
    HDU 1575 Tr A
    toj 2843 Diamonds
    HDU 1856 More is better
    toj 2841 Bitwise Reverse
    hdu 1213 How Many Tables
  • 原文地址:https://www.cnblogs.com/acmdeweilai/p/3306051.html
Copyright © 2020-2023  润新知