Machine trial-deformation of Yang Hui triangle,Yang Hui
Deformed Yang Hui triangle
Each number is the sum of three numbers on the uplink and left and right, and the value 0 does not exist. Locate the position where the first even number of the nth row appears, and no output is-1.
# Include <iostream> using namespace std; int main (int argc, char * argv []) {int n, s, e; cin> n; int a [101] [201] = {0}; // selection of array capacity, considering the calculation of the n-th row, the vertical mark must be + 2 a [1] [100] = 1; for (int I = 2; I <= n; I ++) {s = 100-i + 1; e = 100 + I-1; for (int j = s; j <= e; j ++) a [I] [j] = a [I-1] [J-1] + a [I-1] [j] + a [I-1] [j + 1];} s = 100-n + 1; e = 100 + n-1; for (int I = s; I <= e; I ++) {if (a [n] [I] % 2 = 0) {cout <I-s + 1 <endl; return 0 ;}} cout <"-1" <endl; return 0 ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.