矩阵找最大值

本文介绍了一种特殊矩阵的生成规则及如何找出该矩阵中的最大值。该矩阵的边界值固定为1,其余各元素为其左侧和上方元素之和。通过递推公式实现了高效求解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

给定一个n * n矩阵a,满足条件:

①对于所有1≤i≤n,ai,1 = a1,i = 1

②在①条件之外的位置,每个位置的值均等于它上面的值与左面的值的和。

请你找到矩阵中最大的数字是多少。

Given a n*n matrix A, which satisfies the conditions:

①for all the position of ai,if 1≤i≤n,ai,1 = a1,i = 1

②beyond the condition ①, each value of the position is equal to the sum of the value of above posotion and the value of left position.

Please find out the largest number in the matrix.

输入

一个整数n,代表矩阵规模。(1≤n≤10)

an integer n, which represents the  scale of the matrix.(1≤n≤10)


输出

一个整数ans,表示矩阵中的最大数字。

an integer ans, which represents the largest number in the matrix.

样例输入

5

样例输出

70

提示

来源


#include <stdio.h>
#include <stdlib.h>
int main() {
int n, a[10][10], i, j;
while(scanf("%d",&n)!= EOF){
for (i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
if (i == 1 || j == 1)
a[i][j] = 1;
else 
a[i][j] = a[i-1][j] + a[i][j-1];
}

}
printf("%d\n", a[n][n]);
}


return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值