Untitled

mail@pastecode.io avatar
unknown
java
4 years ago
627 B
2
Indexable
Never
    static int go(int i, int mask, int[][] dp, boolean[][] edges) {
        if(i >= edges.length) return 0;
        if(dp[i][mask] != -1) return dp[i][mask];
        if((mask & (1 << i)) == 1) {
            dp[i][mask] = go(i + 1, mask, dp, edges);
        } else {
            dp[i][mask] = go(i + 1, mask | (1<<i), dp, edges);
            for(int j = 0; j < edges[i].length; j++) {
                if(edges[i][j] && (mask & (1 << j)) == 0) {
                    dp[i][mask] = Math.max(dp[i][mask], 2 + go(i+1, mask | (1 << j) | (1<<i), dp, edges));
                }
            }
        }
        return dp[i][mask];
    }