Skip to content

Instantly share code, notes, and snippets.

@ha2ne2
Created February 9, 2014 03:41
Show Gist options
  • Select an option

  • Save ha2ne2/8893937 to your computer and use it in GitHub Desktop.

Select an option

Save ha2ne2/8893937 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int memo[50];
class CorporationSalary
{
public:
vector <string> data;
int size;
long long getSalary(int n) {
if (memo[n] != 0) return memo[n];
long long result = 0;
for (int i=0; i<size; i++) {
if (data[n][i] == 'Y') {
result += getSalary(i);
}
}
return memo[n] = (result==0)? 1: result;
}
long long totalSalary(vector <string> relations) {
data = relations;
size = relations[0].size();
long long result=0;
for (int i=0; i<size; i++) {
result += getSalary(i);
}
return result;
}
};
void array_init(int* array, int size, int value) {
for (int i=0; i<size; i++) {
array[i] = value;
}
}
int main() {
array_init(memo,50,0);
CorporationSalary c;
cout << c.totalSalary({"NNNNNN",
"YNYNNY",
"YNNNNY",
"NNNNNN",
"YNYNNN",
"YNNYNN"}) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment