Created
February 9, 2014 03:41
-
-
Save ha2ne2/8893937 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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