zoukankan      html  css  js  c++  java
  • toj 2843 Diamonds

    2843.   Diamonds
    Time Limit: 1.0 Seconds   Memory Limit: 65536K
    Total Runs: 856   Accepted Runs: 510



    As we know, Hawk is a great explorer. In the spring of 2007, he decides to go to climb the Asian Coldest Mountain (ACM) and to look for diamonds.

    When Hawk comes to the foot of the mountain, the autochthons told him a great secret. There are many caves in the mountain. And each cave stores three diamonds: a red diamond (ruby), a blue diamond (sapphire), and a purple diamond (amethyst). The explorer can take only one diamond from each cave; otherwise the god will punish the greedy man.

    Along the mountain, there are hundreds of caves. The caves are located in a straight line, and the explorer will go through the line, visiting the caves one after another. Hawk knows the values of the diamonds in each cave. Since he wants to make an exciting trip, he won't choose the same kind of diamonds in any two consecutive caves. That means, if Hawk choose a red diamond in this cave, then he won't choose the red one in the next cave.

    Now, Hawk asks you to help him to determine how to pick the diamonds. He will tell you the values of diamonds in each cave. Please calculate the maximum value that Hawk can achieve.

    Input

    There will be multiple cases for you to calculate.

    The first line of the input contains an integer t (1 ≤ t ≤ 100), which denotes the number of cases. Then t cases followed. Each case begins with an integer n (1 ≤ n ≤ 10000), which denotes the number of caves. Then n lines followed, each line contains 3 integers, the number in the i-th line denote the values of the red diamond, the blue diamond, and the purple diamond in the i-th cave, respectively. The value of any diamond will be non-negative integer and less than 1000.

    Output

    For each case, please output a line containing the maximum value that Hawk can achieve.

    Sample Input

    2
    3
    1 5 7
    3 2 9
    2 10 4
    4
    1 4 7
    2 5 8
    9 6 3
    1 5 9
    

    Sample Output

    24
    30
    

    Problem Setter: cnHawk



    Source: Tianjin Metropolitan Collegiate Programming Contest 2007


    Submit   List    Runs   Forum   Statistics

    Show Code - Run ID 634040
    Submit Time: 
    2009-05-09 18:40:07     Language: GNU C++     Result: Accepted
        Pid: 
    2843     Time: 0.02 sec.     Memory: 1356 K.     Code Length: 0.7 K.

    --------------------------------------------------------------------------------

    #include 
    <iostream>
    #define MAX 10002
    using namespace std;
    int data[MAX][4];
    int GetMax(int a,int b)
    {
        
    if(a>b)
            
    return a;
        
    else
            
    return b;
    }
    int main()
    {
        
    int t,n,a,i,j;
        cin
    >>t;
        
    while(t--)
        {
            cin
    >>n;
            
    for(i=1;i<=n;i++)
                
    for(j=1;j<=3;j++)
                {
                    scanf(
    "%d",&data[i][j]);
                }
            
    int MM=-1,temp;
            
    for(i=n-1;i>=1;i--)
            {
                
    for(j=1;j<=3;j++)
                {
                    
    if(j==1)
                        temp
    =GetMax(data[i+1][2],data[i+1][3]);
                    
    if(j==2)
                        temp
    =GetMax(data[i+1][1],data[i+1][3]);
                    
    if(j==3)
                        temp
    =GetMax(data[i+1][1],data[i+1][2]);
                    data[i][j]
    =data[i][j]+temp;
                    
    if(data[i][j]>MM)
                        MM
    =data[i][j];
                }
            }
            printf(
    "%d\n",MM);
        }
        
    return 0;
    }

    --------------------------------------------------------------------------------

    Tianjin University Online Judge v1.
    2.4

  • 相关阅读:
    论.Net 2.0消失的虚拟内存空间
    检查IE版本的方法
    升级.Net 4.0遇到的两个问题
    关于ID生成算法
    探秘.Net 4.0的StringBuilder实现
    关于填充DataTable的效率问题
    [已解决]请教:时间格式“2008109公元 10:43:27,AM”,这种时间格式是该怎么恢复默认设置
    请教:c#中的窗体怎么才能像c++的那窗体一样按键后可以调出输入法?
    在access中执行SQL,SQL中包含IIF,取出来的结果集字符串被截断了,请教各位大侠,这个是为什么呀?谢谢!
    请教:PL/SQL中执行to_date(to_char(a.lastupdatedate, 'YYYYMMDD HH24:MI:SS'),'YYYYMMDD HH24:MI:SS') ,上午12点整为什么格式化出来没有时分秒?
  • 原文地址:https://www.cnblogs.com/forever4444/p/1453432.html
Copyright © 2011-2022 走看看