TJU : 2843 (Diamonds)


// http://acm.tju.edu.cn/toj/showp2843.html

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <math.h>
#define pi acos(-1.0)
#define N 1000000
using namespace std;

int maximum;
int caves;

int main ()
{
    int testCase;
    scanf ("%d", &testCase);

    while ( testCase-- ) {
        scanf ("%d", &caves);

        int diamondR, diamondB, diamondP;
        int maxR = 0, maxB = 0, maxP = 0;

        for ( int i = 0; i < caves; i++ ) {
            scanf ("%d %d %d", &diamondR, &diamondB, &diamondP);

            diamondR += max ( maxB, maxP );
            diamondB += max ( maxR, maxP );
            diamondP += max ( maxR, maxB );

            maxR = diamondR;
            maxB = diamondB;
            maxP = diamondP;
        }

        maximum = max ( maxR, max ( maxB, maxP ) );

        printf ("%d\n", maximum);
    }

    return 0;
}

// @END_OF_SOURCE_CODE
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s