寒假10.1

An n?×?n table a is defined as follows:
The first row and the first column contain ones, that is: ai,?1?=?a1,?i?=?1 for all i?=?1,?2,?...,?n.
Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula ai,?j?=?ai?-?1,?j?+?ai,?j?-?1.
These conditions define all the values in the table.
You are given a number n. You need to determine the maximum value in the n?×?n table defined by the rules above.
Input
The only line of input contains a positive integer n (1?≤?n?≤?10) — the number of rows and columns of the table.
Output
Print a single line containing a positive integer m — the maximum value in the table.
Examples
Input
1
Output
1
Input
5
Output
70
Note
In the second test the rows of the table look as follows:
{1,?1,?1,?1,?1},?
{1,?2,?3,?4,?5},?
{1,?3,?6,?10,?15},?
{1,?4,?10,?20,?35},?
{1,?5,?15,?35,?70}.

定義一個(gè)二維數(shù)組,讓其第一行和第一列為1,其余由其加得,輸出最后一個(gè)數(shù)即可。

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[11][11];
    for (int i = 0; i < n; i++)
    {
        a[0][i] = 1;
    }
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (j == 0)
            {
                a[i][j] = 1;
            }
            else
                a[i][j] = a[i][j - 1] + a[i - 1][j];
        }
    }
    cout << a[n-1][n-1];
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 數(shù)組在程序設(shè)計(jì)中,為了處理方便, 把具有相同類型的若干變量按有序的形式組織起來。這些按序排列的同類數(shù)據(jù)元素的集合稱...
    朱森閱讀 4,270評(píng)論 2 13
  • 指針是C語言中廣泛使用的一種數(shù)據(jù)類型。 運(yùn)用指針編程是C語言最主要的風(fēng)格之一。利用指針變量可以表示各種數(shù)據(jù)結(jié)構(gòu); ...
    朱森閱讀 3,614評(píng)論 3 44
  • 第四天 數(shù)組【悟空教程】 第04天 Java基礎(chǔ) 第1章數(shù)組 1.1數(shù)組概念 軟件的基本功能是處理數(shù)據(jù),而在處理數(shù)...
    Java幫幫閱讀 1,681評(píng)論 0 9
  • 每個(gè)女人一定都有過這樣的夢(mèng)想:陽光暖暖、窗紗飄渺、音樂絲絲入耳、咖啡冒著熱氣、屋子里窗明幾凈、自己懶洋洋的窩在沙發(fā)...
    小十小十小小十閱讀 932評(píng)論 2 11
  • 半塊殘玉懸蒼穹,一箋心事掛疏桐。 天涯故人莫相問,半世蹉跎半世夢(mèng)。
    秦川明月閱讀 524評(píng)論 0 2

友情鏈接更多精彩內(nèi)容