4e494b's blog

By 4e494b, history, 5 years ago, In English

Hello codeforces community, I need your help again.

I was solving this problem on SPOJ. I did it using top-down approach and when I tried to convert it to bottom-up, I just could not think of base cases. So I googled for the bottom up solution of this problem. I was taken to this Topcoder Link. I tried to understand the logic behind dp[1][1] = 1, but I just could not wrap my head around it.

It would be really helpful, if you could explain me your own technique (bottom-up ofc) to solve this problem or explain the reasoning behind the dp state in topcoder article.

Here is my top-down code

#include<bits/stdc++.h>

using namespace std;

int dp[610][610];
int H[250];
int W[250];
int n;

int sol(int w, int h){
    int res = w*h;
    if(dp[w][h] != -1){
        return dp[w][h];
    }
    for(int i=0; i<n; i++){
        if(w - W[i] >= 0 && h - H[i] >= 0){
            res = min(res, sol(w-W[i],h)+sol(W[i],h-H[i]));
            res = min(res, sol(w,h-H[i])+sol(w-W[i],H[i]));
        }
    }
    dp[w][h] = res;
    return dp[w][h];
}

int main()
{
    int t;
    cin >> t;
    while(t--){
        int w,h;
        cin >> w >> h;
        cin >> n;
        for(int i=0; i<n; i++){
            cin >> W[i] >> H[i];
        }
        memset(dp, -1, sizeof(dp));
        cout << sol(w,h) << endl;
    }
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By 4e494b, history, 5 years ago, In English

Hello codeforces community.

I was trying to solve question 234C from codeforces round #145 and I could not come up with a scheme/way to solve it. So I tried looking for the editorials for this round but could not find it. Also, I looked at successful submission but could not understand the intended solution for this problem.

It would help me if you could share your approach on how you would solve this problem.

Thank You.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By 4e494b, history, 5 years ago, In English

MikeMirzayanov please look into it, as i can not access my, "favorite blogs". I had searched for the blogs and saved them as favorites (by clicking on the star), but now when i click on favorite section, it shows ACCESS DENIED. Please help.

UPD: This issue is fixed now.

Full text and comments »

  • Vote: I like it
  • +54
  • Vote: I do not like it