Skip to content

Instantly share code, notes, and snippets.

@A-gambit
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save A-gambit/dcff5224839a2904ee58 to your computer and use it in GitHub Desktop.

Select an option

Save A-gambit/dcff5224839a2904ee58 to your computer and use it in GitHub Desktop.
#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;
}
#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");
}
#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