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;
    }
    
  • 相关阅读:
    Struts系列教材 (四)- 基础
    Struts系列教材 (三)- 基础
    Struts系列教材 (一)- 基础
    Hibernate系列教材 (三十)- 注解
    网络之AFNetworking
    iOS网络学习之“远离NSURLConnection 走进NSURLSession”
    ios中常见数据存储方式以及SQLite常用的语句
    利用"仿射变换"制作“酷炫特效”
    图片滚动新闻和新闻的滚动菜单
    简易聊天窗口
  • 原文地址:https://www.cnblogs.com/fusiwei/p/13711951.html
Copyright © 2011-2022 走看看