Partially correct - Time limit exceeded


#1

How can I improve this code :-

public int solve(int eggs, int floors) {
int[][] dp = new int[eggs + 1][floors + 1];
for(int i = 0; i <= floors; i++) {
dp[1][i] = i;
}

    int c = 0;
    for(int e = 2; e <= eggs; e++) {
        for(int f = 1; f <= floors; f++) {
            dp[e][f] = Integer.MAX_VALUE;
            for(int k = 1; k <= f; k++) {
                c = 1 + Math.max(dp[e - 1][k - 1], dp[e][f - k]);
                if(c < dp[e][f]) {
                    dp[e][f] = c;
            }
            }
           
        }
    }
    
    return dp[eggs][floors];
}

#2

Try to simplify the recurrence relation.
Then problem will be reduced to finding a binomial coefficient and we can easily do that with binary search.