zoukankan      html  css  js  c++  java
  • CF295C Greg and Friends

    CF509A Maximum in Table

    洛谷传送门

    题目描述

    An n×nn×n table aa is defined as follows:

    • The first row and the first column contain ones, that is: a_{i,1}=a_{1,i}=1a**i,1=a1,i=1 for all i=1,2,...,ni=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 a_{i,j}=a_{i-1,j}+a_{i,j-1}a**i,j=a**i−1,j+a**i,j−1 .

    These conditions define all the values in the table.

    You are given a number nn . You need to determine the maximum value in the n×nn×n table defined by the rules above.

    输入格式

    The only line of input contains a positive integer nn ( 1<=n<=101<=n<=10 ) — the number of rows and columns of the table.

    输出格式

    Print a single line containing a positive integer mm — the maximum value in the table.

    题意翻译

    给定一个 NN * NN 的矩阵,令 a_{i,j}a**i,j 为矩阵中第i行第j列的元素,则有:

    1. a_{k,1}=a_{1,k}=1(1≤k≤N)a**k,1=a1,k=1(1≤kN)
    2. a_{i,j}=a_{i-1,j}+a_{i,j-1}(2≤i,j≤N)a**i,j=a**i−1,j+a**i,j−1(2≤i,jN) 现请求出该矩阵中最大元素的值。 输入格式: 一行一个正整数 N(N ≤ 10)N(N≤10) 。 输出格式: 一行一个正整数表示上述答案。

    输入输出样例

    输入 #1复制

    输出 #1复制

    输入 #2复制

    输出 #2复制

    说明/提示

    In the second test the rows of the table look as follows:

    {1,1,1,1,1},1,1,1,1,1, {1,2,3,4,5},1,2,3,4,5, {1,3,6,10,15},1,3,6,10,15, {1,4,10,20,35},1,4,10,20,35, {1,5,15,35,70}.1,5,15,35,70.

    题解:

    哎,又要被骂刷水题了。

    依题意模拟即可。

    代码:

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int n,ans=1;
    int map[20][20];
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            map[1][i]=map[i][1]=1;
        for(int i=2;i<=n;i++)
            for(int j=2;j<=n;j++)
            {
                map[i][j]=map[i-1][j]+map[i][j-1];
                ans=max(ans,map[i][j]);
            }
        printf("%d",ans);
        return 0;
    }
    
  • 相关阅读:
    调试PHP如何让浏览器提示错误
    接口的理解
    linux中的curl
    linux后台执行命令:&和nohup
    php定界符<<<EOF讲解
    有关字符集问题
    设置disabled属性
    PHP魔术常量
    phpstorm-有关设置
    php常用函数
  • 原文地址:https://www.cnblogs.com/fusiwei/p/13711951.html
Copyright © 2011-2022 走看看