Skip to content

Instantly share code, notes, and snippets.

@hodduc
Created April 16, 2013 08:59
Show Gist options
  • Save hodduc/5394477 to your computer and use it in GitHub Desktop.
Save hodduc/5394477 to your computer and use it in GitHub Desktop.
SRM 503 Easy
#include<vector>
#include<algorithm>
using namespace std;
int d[55][55];
class ToastXToast
{
public:
int bake(vector <int> under, vector <int> over){
sort(under.begin(), under.end());
sort(over.begin(), over.end());
int n, m;
n = under.size(); m = over.size();
int i, j, k, l;
for(i = 0; i <= n; i++) for(j = 0; j <= m; j++) d[i][j] = 9999999;
d[0][0] = 0;
for(i = 1; i <= n; i++) for(j = 1; j <= m; j++){
for(k = 0; k < i; k++) for(l = 0; l < j; l++){
if(under[i-1] < over[l] && d[i][j] > d[k][l]+1) d[i][j] = d[k][l]+1;
}
}
if(d[n][m] == 9999999) return -1;
return d[n][m];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment