Java memorized DFS
\nclass Solution {\n    Map<String, Integer> cache = new HashMap<>();\n    public boolean stoneGameIX(int[] stones) {\n        int[] count = new int[3];\n      
```\nclass Solution {\n    Map<String, Integer> cache = new HashMap<>();\n    public boolean stoneGameIX(int[] stones) {\n        int[] count = new int[3];\n        for (int s : stones) {\n            count[s % 3]++;\n        }\n        count[0] %= 2;\n        return dfs(count, -1, 0) == -1;\n    }\n    private int dfs(int[] count, int f, int sum) {\n        if (count[0] == 0 && count[1] == 0 && count[2] == 0) return 1;\n        String key = count[0] + " " + count[1] + " " + count[2] + " " + f;\n        if (cache.containsKey(key)) return cache.get(key); \n        int res = -f;\n        for (int i = 0; i < 3; i++) {\n            if (count[i] > 0) {\n                count[i]--;\n                if ((sum + i) % 3 != 0 && dfs(count, -f, (sum + i) % 3) == f) {\n                    res = f;\n                } \n                count[i]++;\n            }\n        }\n        cache.put(key, res);\n        return res;\n    }\n}\n```
[]