구두 산술 퍼즐

2020년 1월 2일 12시 9분 9초

문제 설명 :

 

문제 해결 :

문제는 초등학교 올림픽 제목이 아니다? 모든 폭력을 알고 열거하지만, 얼마나 영리 열거하는 것은 중요한 문제입니다합니다. 재생, 나는 전체 순위 알고리즘, TLE 위로를 보냈다.

정말 기록을 너무 이것으로, 우아함을 많이 달성하기 위해, 다른 사람의 솔루션에서 알아보세요.

    공개 INT는 [] pow_num 새로운 지능 = [{1, 10, 100, 1000, 10000, 100000, 1000000};
    공개 부울 isSolvable (문자열 [] 즉, 문자열 결과) {
        집합은 <특성> 본 = 새로운 HashSet의 <> ();
        부울 [] isFirst 새로운 부울 [128] =;
        INT는 [] char_count 새로운 INT [128] =;
        {: (단어 문자열 단어)에 대한
            경우 (나는 <word.length (); INT 나 0 = I ++) {
                숯 C = word.charAt (I);
                경우 (isFirst [C] == 0 && I && word.length ()> 1!) isFirst [C] = TRUE;
                char_count [C] + = pow_num [word.length () - I - 1];
                (c) seen.add;
            }
        }
        for (int i = 0; i < result.length(); i++) {
            char c = result.charAt(i);
            if (!isFirst[c] && i == 0 && result.length() > 1) isFirst[c] = true;
            char_count[c] -= pow_num[lresult.length() - i - 1];
            seen.add(c);
        }
        char[] chs = new char[seen.size()];
        int idx = 0;
        for (char c : seen) chs[idx++] = c;
        return helper(char_count, isFirst, chs, new boolean[10], 0, 0);
    }
    
    private boolean helper(int[] char_count, boolean[] isFirst, char[] chs, boolean[] used, int step, int diff) {
        if (step == chs.length) return diff == 0;
        for (int i = 0; i < 10; i++) {
            char c = chs[step];
            if (used[i] || (i == 0 && isFirst[c])) continue;
            used[i] = true;
            if (helper(char_count, isFirst, chs, used, step + 1, diff + char_count[c] * i)) return true;
            used[i] = false;
        }
        return false;
    }

  

 

추천

출처www.cnblogs.com/hyserendipity/p/12132264.html