Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- int n;
- int mat[100005][3];
- int dp[100005][3];
- int main(){
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> mat[i][0] >> mat[i][1] >> mat[i][2];
- dp[i][0] = dp[i][1] = dp[i][2] = -2e9;
- }
- dp[0][0] = mat[0][0];
- dp[0][1] = mat[0][1];
- dp[0][2] = mat[0][2];
- for(int day = 0; day + 1 < n; day++) {
- for(int prev_activity = 0; prev_activity < 3; prev_activity++) {
- for(int next_activity = 0; next_activity < 3; next_activity++) {
- if(prev_activity != next_activity) {
- dp[day + 1][next_activity] = max(dp[day + 1][next_activity], dp[day][prev_activity] + mat[day + 1][next_activity]);
- }
- }
- }
- }
- cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement