Last active
August 29, 2015 14:20
-
-
Save A-gambit/dcff5224839a2904ee58 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> | |
| using namespace std; | |
| int main(int argc, char *argv[]){ | |
| FILE *file; | |
| int things[500][2], weight = 0, numbers = 0; | |
| int cur[20001], res[20001]; | |
| cout<<"Hello, World"<<endl; | |
| file = fopen(argv[1], "r"); | |
| fscanf(file, "%d", &weight); | |
| fscanf(file, "%d", &numbers); | |
| for (int i = 0; i < weight; i++){ | |
| fscanf(file, "%d", &things[i][0]); | |
| fscanf(file, "%d", &things[i][1]); | |
| } | |
| for (int i = 0; i <= weight; i++){ | |
| cur[i] = 0; | |
| } | |
| for (int i = 1; i <= numbers; i++){ | |
| for (int j = 0; j <= weight; j++){ | |
| res[j] = cur[j]; | |
| } | |
| for (int j = things[i][1]; j <= weight; j++) { | |
| int val = res[j-things[i][1]] + things[i][0]; | |
| if (res[j] < val) { | |
| cur[j] = val; | |
| } | |
| } | |
| } | |
| cout << cur[weight] << endl; | |
| return 0; | |
| } |
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> | |
| using namespace std; | |
| int main(int argc, char *argv[]){ | |
| FILE *file; | |
| int things[500][2], weight = 0, numbers = 0; | |
| int* cur = new int[2000001]; | |
| int* res = new int[2000001]; | |
| cout<<"Hello, World"<<endl; | |
| file = fopen(argv[1], "r"); | |
| fscanf(file, "%d", &weight); | |
| fscanf(file, "%d", &numbers); | |
| for (int i = 0; i < weight; i++){ | |
| fscanf(file, "%d", &things[i][0]); | |
| fscanf(file, "%d", &things[i][1]); | |
| } | |
| for (int i = 0; i <= weight; i++){ | |
| cur[i] = 0; | |
| } | |
| for (int i = 1; i <= numbers; i++){ | |
| for (int j = 0; j <= weight; j++){ | |
| res[j] = cur[j]; | |
| } | |
| for (int j = things[i-1][1]; j <= weight; j++) { | |
| int val = res[j-things[i-1][1]] + things[i-1][0]; | |
| if (res[j] < val) { | |
| cur[j] = val; | |
| } | |
| } | |
| } | |
| cout << cur[weight] << endl; | |
| system("pause"); | |
| } |
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> | |
| using namespace std; | |
| int main(int argc, char *argv[]){ | |
| FILE *file; | |
| int things[500][2], weight = 0, numbers = 0; | |
| int* cur = new int[2000001]; | |
| int* res = new int[2000001]; | |
| file = fopen(argv[1], "r"); | |
| fscanf(file, "%d", &weight); | |
| fscanf(file, "%d", &numbers); | |
| for (int i = 0; i < numbers; i++){ | |
| fscanf(file, "%d", &things[i][0]); | |
| fscanf(file, "%d", &things[i][1]); | |
| } | |
| for (int i = 0; i <= weight; i++){ | |
| cur[i] = 0; | |
| } | |
| for (int i = 0; i < numbers; i++){ | |
| for (int j = 0; j <= weight; j++){ | |
| res[j] = cur[j]; | |
| } | |
| for (int j = things[i][1]; j <= weight; j++) { | |
| int val = res[j-things[i][1]] + things[i][0]; | |
| if (res[j] < val) { | |
| cur[j] = val; | |
| } | |
| } | |
| } | |
| cout << cur[weight] << endl; | |
| system("pause"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment