Advertisement
Graf_Rav

Danov1802 27.3

May 25th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     int n;
  9.     cin>>n;
  10.    
  11.     vector< vector<int> > ways(n, vector<int>(2, -0x80000000)); //[][0]чет   [][1]нечет
  12.     ways[0][0]=0;
  13.    
  14.     for(int j=1;j<n;j++){
  15.         int a;
  16.         cin>>a;
  17.         if(ways[j-1][0] != -0x80000000){
  18.             ways[j][abs((ways[j-1][0]+a)%2)]=ways[j-1][0]+a;
  19.         }
  20.         if(ways[j-1][1] != -0x80000000){
  21.             ways[j][abs((ways[j-1][1]+a)%2)]=ways[j-1][1]+a;
  22.         }
  23.     }
  24.    
  25.     for(int i=1;i<n;i++){
  26.         for(int j=0;j<n;j++){
  27.             int a;
  28.             cin>>a;
  29.            
  30.             vector<int> buffer (2, -0x80000000);
  31.            
  32.             if(ways[j][0] != -0x80000000){
  33.                 buffer[abs((ways[j][0]+a)%2)]=ways[j][0]+a;
  34.             }
  35.            
  36.             if(ways[j][1] != -0x80000000){
  37.                 buffer[abs((ways[j][1]+a)%2)]=ways[j][1]+a;
  38.             }
  39.            
  40.             ways[j] = buffer;
  41.         }
  42.        
  43.         for(int j=1;j<n;j++){
  44.             int a;
  45.             cin>>a;
  46.            
  47.             if(ways[j-1][0] != -0x80000000){
  48.                 ways[j][abs((ways[j-1][0]+a)%2)]=max(ways[j][abs((ways[j-1][0]+a)%2)] , ways[j-1][0]+a);
  49.             }
  50.            
  51.             if(ways[j-1][1] != -0x80000000){
  52.                 ways[j][abs((ways[j-1][1]+a)%2)]=max(ways[j][abs((ways[j-1][1]+a)%2)] , ways[j-1][1]+a);
  53.             }
  54.            
  55.         }
  56.     }
  57.    
  58.     if(ways[n-1][0] == -0x80000000){
  59.         cout<<n;
  60.     }
  61.     else{
  62.         cout<<ways[n-1][0];
  63.     }
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement