Machine trial-deformation of Yang Hui triangle,Yang Hui

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.