Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- using namespace std;
- int main(){
- int n;
- cin>>n;
- vector< vector<int> > ways(n, vector<int>(2, -0x80000000)); //[][0]чет [][1]нечет
- ways[0][0]=0;
- for(int j=1;j<n;j++){
- int a;
- cin>>a;
- if(ways[j-1][0] != -0x80000000){
- ways[j][abs((ways[j-1][0]+a)%2)]=ways[j-1][0]+a;
- }
- if(ways[j-1][1] != -0x80000000){
- ways[j][abs((ways[j-1][1]+a)%2)]=ways[j-1][1]+a;
- }
- }
- for(int i=1;i<n;i++){
- for(int j=0;j<n;j++){
- int a;
- cin>>a;
- vector<int> buffer (2, -0x80000000);
- if(ways[j][0] != -0x80000000){
- buffer[abs((ways[j][0]+a)%2)]=ways[j][0]+a;
- }
- if(ways[j][1] != -0x80000000){
- buffer[abs((ways[j][1]+a)%2)]=ways[j][1]+a;
- }
- ways[j] = buffer;
- }
- for(int j=1;j<n;j++){
- int a;
- cin>>a;
- if(ways[j-1][0] != -0x80000000){
- ways[j][abs((ways[j-1][0]+a)%2)]=max(ways[j][abs((ways[j-1][0]+a)%2)] , ways[j-1][0]+a);
- }
- if(ways[j-1][1] != -0x80000000){
- ways[j][abs((ways[j-1][1]+a)%2)]=max(ways[j][abs((ways[j-1][1]+a)%2)] , ways[j-1][1]+a);
- }
- }
- }
- if(ways[n-1][0] == -0x80000000){
- cout<<n;
- }
- else{
- cout<<ways[n-1][0];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement