Skip to content

Instantly share code, notes, and snippets.

@garasubo
Created November 7, 2014 05:34
Show Gist options
  • Save garasubo/63ee30e3deb44b686acc to your computer and use it in GitHub Desktop.
Save garasubo/63ee30e3deb44b686acc to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define INF (1 << 29)
#define rep2(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
class ChocolateDividingEasy{
int memo[60][60][60][60];
int func(int i,int j, int k, int l){
int &mm = memo[i][j][k][l];
if(mm==-1){
mm = 0;
if(j==l){
mm+=func(i,j,k-1,l);
mm+=func(k,j,k,l);
} else {
mm+=func(i,l,k,l);
mm+=func(i,j,k,l-1);
}
}
return mm;
}
public:
ChocolateDividingEasy() {}
int findBest(vector<string> choco){
int res = 0;
int wid = choco.size();
int hei = choco[0].size();
memset(memo,-1,sizeof(memo));
rep(i,wid) rep(j,hei) memo[i][j][i][j] = choco[i][j]-'0';
rep(k,hei) rep(i,wid) rep2(j,i+1,wid) {
memo[i][k][j][k] = memo[i][k][j-1][k]+memo[j][k][j][k];
}
rep(k,wid) rep(i,hei) rep2(j,i+1,hei) {
memo[k][i][k][j] = memo[k][i][k][j-1]+memo[k][j][k][j];
}
rep2(i,1,wid) rep2(j,1,hei) rep2(k,i+1,wid-1) rep2(l,k+1,hei-1){
int tmp = INF;
tmp = min(tmp,func(0,0,i-1,j-1));
tmp = min(tmp,func(0,j,i-1,l-1));
tmp = min(tmp,func(0,l,i-1,hei-1));
tmp = min(tmp,func(i,0,k-1,j-1));
tmp = min(tmp,func(i,j,k-1,l-1));
tmp = min(tmp,func(i,l,k-1,hei-1));
tmp = min(tmp,func(k,0,wid-1,j-1));
tmp = min(tmp,func(k,j,wid-1,l-1));
tmp = min(tmp,func(k,l,wid-1,hei-1));
res = max(res,tmp);
}
return res;
}
};
int main()
{
vector<string> ch;
cout << "java" << endl;
ch.push_back("9768");
ch.push_back("6767");
ch.push_back("5313");
ChocolateDividingEasy tar;
cout << tar.findBest(ch) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment