QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#218262#5598. Profitable TripViktorML 1ms4104kbC++141.5kb2023-10-17 21:56:012023-10-17 21:56:01

Judging History

你现在查看的是最新测评结果

  • [2023-10-17 21:56:01]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:4104kb
  • [2023-10-17 21:56:01]
  • 提交

answer

#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>> points[10000];  //graph
int visited_scores[10000];      //Scores of visited points
vector<int> way_scores;         //Summarize scores of all routes
int n,m,w;      //InputVariables

void reset_visited();
void best_effort(int actual_position, int score);

int main() {
    reset_visited();
    //Input
    cin >> n >> m >> w;

    int from, to, cost;
    for (int i = 0; i < m; i++) {
        cin >> from >> to >> cost;
        points[from].push_back({to, cost});
    }

    best_effort(1,0);
    int max_coins = -300;

    int size = way_scores.size();       //sequential search
    for (int i = 0; i < size; i++) {
        if (way_scores[i] > max_coins) { max_coins = way_scores[i]; }
    }

    cout << max_coins << endl; 
    return 0;
}


void best_effort(int actual_position, int score) {
    if (actual_position == n && (points[actual_position].empty() || visited_scores[actual_position] == score)) { way_scores.push_back(score); reset_visited(); }
    else {
        visited_scores[actual_position] = score;
        int new_score;
        int size = points[actual_position].size();
        for (int i = 0; i < size; i++) {
            new_score = score + points[actual_position][i][1] > w ? w : score + points[actual_position][i][1];
            best_effort(points[actual_position][i][0], new_score);
        }
    }
}

void reset_visited() { for (int i = 0; i < 10000; i++) { visited_scores[i] = -200; } } //make the visited scores unvisited

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3868kb

input:

2 1 10
1 2 0

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

4 4 9
1 2 5
1 3 -2
2 4 1
3 4 10

output:

8

result:

ok single line: '8'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

4 4 7
1 2 5
1 3 -2
2 4 1
3 4 10

output:

7

result:

ok single line: '7'

Test #4:

score: 0
Accepted
time: 0ms
memory: 4104kb

input:

3 3 5
1 3 -10
3 2 2
2 3 -1

output:

4

result:

ok single line: '4'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

2 1 10
1 2 1

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

2 1 10
1 2 -1

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

2 2 10
1 2 1
2 1 -1

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 0ms
memory: 4092kb

input:

2 2 10
1 2 -1
2 1 2

output:

9

result:

ok single line: '9'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

2 2 10
1 2 2
2 1 -1

output:

10

result:

ok single line: '10'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

3 2 10
1 2 3
2 3 3

output:

6

result:

ok single line: '6'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

5 5 100
1 2 100
2 3 100
3 4 100
4 5 100
5 1 100

output:

100

result:

ok single line: '100'

Test #12:

score: -100
Memory Limit Exceeded

input:

5 5 100
1 2 -100
2 3 -100
3 4 -100
4 5 -100
5 1 -100

output:


result: