Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submissão do problema 01 #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions submissions/FelipMa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# FelipMa

To compile and run the code, use the following command:

```
gcc problema-1.c -O3 -o problema-1 && ./problema-1 ../../resources/instances/problem_01/exemplo_03.txt
```

`../../resources/instances/problem_01/exemplo_03.txt` is the relative path to the test file, from "FelipMa" folder.
31 changes: 31 additions & 0 deletions submissions/FelipMa/problema-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>

int main(int argc, char *argv[]) {
FILE *file;

file = fopen(argv[1], "r");

int n_seeds;
fscanf(file, "%d", &n_seeds);

int n_spaces;
fscanf(file, "%d", &n_spaces);

int profits[2667] = {0};

for (int i = 0; i < n_seeds; i++) {
int seed_size;
fscanf(file, "%d", &seed_size);

int seed_value;
fscanf(file, "%d", &seed_value);

for (int space = n_spaces; space >= seed_size; --space) {
profits[space] = (profits[space] >= profits[space - seed_size] + seed_value) ? profits[space] : profits[space-seed_size] + seed_value;
}
}

printf("%d\n", profits[n_spaces]);
fclose(file);
return 0;
}