美文网首页
寒假10.1

寒假10.1

作者: wolfway_d0ff | 来源:发表于2019-01-29 23:45 被阅读0次

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}.

定义一个二维数组,让其第一行和第一列为1,其余由其加得,输出最后一个数即可。

#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;
}

相关文章

  • 寒假10.1

    An n × n table a is defined as follows:The first row and ...

  • 白于舟:9.30黄金下周走势分析,下周黄金怎么操作?黄金看多看空

    文章摘要:9.30-10.1黄金前言;9.30-10.1黄金昨日行情回顾;9.30-10.1黄金为何暴涨?9.30...

  • conda虚拟环境中安装cuda

    虚拟环境里面安装cuda10.1 conda install cudatoolkit=10.1

  • Codility每周一课:L10 Prime and compo

    P10.1 CountFactors Count factors of given number n. P10.1...

  • 10.13卡-熊志华

    10.1

  • 10.1

    只是不希望 你为一朵花低眉 为一滴雨感动 的柔情 淹没了 曾经的豪情万丈。 毕竟 奋斗的路上 来不及停留和感伤 。...

  • 10.1

    虽说孩子不上学,不定闹钟的。心里也是放松的。奈何生物钟是不会轻易而变。依旧5.40左右醒了,懒懒吧。随手拿起孩子的...

  • 10.1

    金秋十月,丹桂飘香。在这个特别的日子,心情总归是不一样的。生日快乐,我的祖国! 好不容易盼来国庆假期,躺在床上...

  • 10.1

    国庆第一天,烦的一批,拉肚子拉的停不下来,喝了一杯草莓味的石灰水,呕!!! 还得抽空改工作的事情,妈个鸡,老子放假...

  • 10.1

    别人看不看的起自己不重要,最重要的是自己永远都看得起自己,坚持是一种信仰!

网友评论

      本文标题:寒假10.1

      本文链接:https://www.haomeiwen.com/subject/onbfsqtx.html