当前位置:网站首页>LeetCode_ 118. Yanghui triangle_ Dynamic programming_ Int * * learning
LeetCode_ 118. Yanghui triangle_ Dynamic programming_ Int * * learning
2022-04-22 08:19:00 【Pattyi】
Given a nonnegative integer numRows, Generate 「 Yang hui triangle 」 Before numRows That's ok .
stay 「 Yang hui triangle 」 in , Each number is the sum of the numbers at the top left and right of it .
Example 1:
Input : numRows = 5
Output : [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
Example 2:
Input : numRows = 1
Output : [[1]]
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/pascals-triangle
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
Use a two-dimensional array :
————————————————
Copyright notice : This paper is about CSDN Blogger 「 Long lasting bangbangjun 」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/lalala_dxf/article/details/120106430
// Yang hui triangle
#include<stdio.h>
#define N 10
int main(void)
{
int i, j, a[N][N];
// Make the numbers on both sides equal 1
for (i = 0; i < N; i++)
{
a[i][0] = a[i][i] = 1;
}
// Except for the numbers on both sides, they are equal to the sum of the above two terms
for (i = 2; i < N; i++)
{
for (j = 1; j < i; j++)
{
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
}
// Control output , The last number in each line has no spaces , There is a space between two adjacent numbers
for (i = 0; i < N; i++)
{
for (j = 0; j < i+1; j++)
{
if (j == i)
printf("%d", a[i][j]);
else
printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}
int** generate(int numRows, int* returnSize, int** returnColumnSizes) {
int** ret = malloc(sizeof(int*) * numRows);
*returnSize = numRows;
*returnColumnSizes = malloc(sizeof(int) * numRows);
for (int i = 0; i < numRows; ++i) {
ret[i] = malloc(sizeof(int) * (i + 1));
(*returnColumnSizes)[i] = i + 1;
ret[i][0] = ret[i][i] = 1;
for (int j = 1; j < i; ++j) {
ret[i][j] = ret[i - 1][j] + ret[i - 1][j - 1];
}
}
return ret;
}
author :LeetCode-Solution
link :https://leetcode-cn.com/problems/pascals-triangle/solution/yang-hui-san-jiao-by-leetcode-solution-lew9/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
Understanding supplement :
int ** The understanding of the :https://yian.me/blog/what-is/pointer-to-pointer-in-c-programing-language.html?utm_source=tuicool&utm_medium=referral
The type of content pointed to by the pointer is different , A pointer to a int Type a point int * type .
int i integer
int* pi Is a pointer to an integer variable 【 What is kept is int Variable of type i The address of 】
int** ppi Point to A pointer to an integer variable The pointer 【 What is kept is int* Variable of type pi The address of 】
版权声明
本文为[Pattyi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220648209442.html
边栏推荐
- numpy append函数
- lnmp mysql 允许远程访问
- 软件测试面试题汇总
- PDH optical transceiver optical fiber transmission 32-way E1 + 4-way 100m 100m network optical transceiver 2m multi service optical transceiver
- tf.keras.layers.Dense函数
- HLS / Chisel 实践CORDIC高性能计算复数平方根
- Data driven pytest1
- 光纤传输16路E1+4路千兆隔离以太网络光端机2M专网千兆以太网综合多业务PDH光端机
- RSYNC及inotify远程同步
- SQL 基础(八)数据更新操作实战演练
猜你喜欢

路由模式的区别

lnmp mysql 允许远程访问

VS Code 设置换行

2022年全国中职组网络安全国赛赛题思路(仅自己一个做题的思路)——网络安全竞赛试题(8)

实验一、数据科学导论——数据科学认知

PDH光端机4路E1+4路百兆以太网 4路2M光端机 FC单纤20公里 机架式

PDH optical transceiver optical fiber transmission 32-way E1 + 4-way 100m 100m network optical transceiver 2m multi service optical transceiver

Hanyuan hi tech 8e1 private network 4-way 100m isolated network PDH optical transceiver E1 private network service 16m service optical transceiver

ACM入门之【容斥定理】

tf.keras.layers.Dense函数
随机推荐
Unity 透视投影矩阵变换的可视化
Data driven pytest1
tf.keras.layers.Embedding函数
OpenFeign组件的简介和使用
荧光标记的透明质酸|FITC-Hyaluronate|荧光素透明质酸|Fluorescent hyaluronic acid
汇编学习《汇编语言(第三版)》王爽著第三章学习
PHP 实现 QQ 登录
tf.keras.layers.InputLayer函数
动态顺序表+OJ
Magnesium oxide MgO crystal substrate | strontium titanate SrTiO3 crystal substrate | lithium niobate LiNbO3 crystal substrate; 10mm diameter
OpenCV对矩形填充透明颜色
JMeter post request
汉源高科8E1专网4路百兆隔离网络PDH光端机E1专网业务16M业务光端机
信息学奥赛一本通 1211:判断元素是否存在 | OpenJudge 1.13 41:判断元素是否存在
TP5 多条件where查询(使用PHP变量)
ACM入门之【容斥定理】
OpenFeign的参数传递之数组和集合类型
AC & A2C & A3C
Mysql Command Line Client 的使用,及常用命令
Network principle II (Part I)
