I found a solution to the 3-partition problem, that is, given n numbers, you determine if you can form three (disjoin) subsets such that all are equal (that is, each subset has a sum equal to the sum of the n numbers/3).
A similar question is at: 3-PARTITION problem. However, I am looking for an explanation of the below code.
Simply put, I have no idea what is going on. I don't know what T is, what i or j are, what k is, or why we k and j start at N and are being decremented, what "T[j + C[i]][k] = true; T[j][k + C[i]] = true" means, or why are we returning T[N/3]?
bool T[10240][10000];
bool partition( vector< int > C ) {
// compute the total sum
int n = C.size();
int N = 0;
for( int i = 0; i < n; i++ ) N += C[i];
// initialize the table
T[0][0] = true;
memset(T, 0, 10000^2);
// process the numbers one by one
for( int i = 0; i < n; i++ ) {
for (int j = N; j >= 0; --j) {
for (int k = N; k >= 0; --k) {
if (T[j][k]) {
T[j + C[i]][k] = true;
T[j][k + C[i]] = true;
}
}
}
}
return T[N / 3];
}