当前位置:网站首页>C, print the source program of beautiful bell triangle
C, print the source program of beautiful bell triangle
2022-04-23 20:59:00 【Deep confusion】
With Bell count Based on , Reference resources Yanghui triangle , It can also generate Bell triangle (Bell triangle), Also known as Aitken array (Aitken's Array), Piece triangle (Peirce Triangle).
Bell triangle Construction method of :
(1) The first element in the first line is 1, namely a[1][1] = 1
(2) about n>1, The first n The first item of the line is equal to the n-1 Line last item , namely a[n][1] = a[n-1][n-1];
(3) about m,n>1, The first n Xing di m The term is equal to the sum of the two numbers on its left and upper left , namely a[n][m] = a[n][m-1] + a[n-1][m-1];

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
namespace Legalsoft.Truffer.Algorithm
{
public static partial class Number_Sequence
{
/// <summary>
/// Bell triangle (Bell triangle)
/// Aitken array (Aitken's Array)
/// Piece triangle (Peirce Triangle)
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static string Bell_Triangle(int n)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("<style>");
sb.AppendLine(".n0 { float:left;width:90px;height:25px;line-height:25px;font-size:14px;text-align:center;border:dotted 1px #993333;background-color:#FFF9F9;margin-right:10px;margin-bottom:10px; } ");
sb.AppendLine(".n1 { float:left;width:90px;height:25px;line-height:25px;font-size:14px;text-align:center;border:dotted 1px #333399;background-color:#F9F9FF;margin-right:10px;margin-bottom:10px; } ");
sb.AppendLine("</style>");
sb.AppendLine("<center>");
long[] last = new long[n + 1];
long[] array = new long[n + 1];
last[0] = 1;
for (int i = 1; i <= n; i++)
{
sb.AppendLine("<table><tr><td>");
array[0] = (i > 1) ? last[i - 2] : last[i - 1];
sb.AppendLine("<div class='n" + (array[0] % 2) + "'>" + array[0] + "</div>");
for (int j = 1; j < i; j++)
{
array[j] = array[j - 1] + last[j - 1];
sb.AppendLine("<div class='n" + (array[j] % 2) + "'>" + array[j] + "</div>");
}
for (int j = 0; j < i; j++)
{
last[j] = array[j];
}
sb.AppendLine("</td></tr></table>");
}
return sb.ToString();
}
}
}
——————————————————————
POWER BY TRUFFER.CN
版权声明
本文为[Deep confusion]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232049142274.html
边栏推荐
- go defer
- 危机即机遇,远程办公效率为何会提升?
- Identifier CV is not defined in opencv4_ CAP_ PROP_ FPS; CV_ CAP_ PROP_ FRAME_ COUNT; CV_ CAP_ PROP_ POS_ Frames problem
- 韩国或将禁止苹果和谷歌向开发者抽佣 创全球首例
- laravel 发送邮件
- go interface
- Leetcode-279-complete square number
- 亚马逊和Epic将入驻,微软应用商城向第三方开放
- 中创存储|想要一个好用的分布式存储云盘,到底该怎么选
- Unity Odin ProgressBar add value column
猜你喜欢

MySQL基础合集

管道和xargs

DeNO 1.13.2 release

What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer

Unity solves Z-fighting

MySQL基础之写表(创建表)

Amazon and epic will be settled, and the Microsoft application mall will be opened to third parties

Thinkphp5 + data large screen display effect

Recommended usage scenarios and production tools for common 60 types of charts

Fastdfs思维导图
随机推荐
Send email to laravel
Sequential state
Express ③ (use express to write interface and cross domain related issues)
Cmake project under vs2019: calculating binocular parallax using elas method
Ubuntu 20 installing centernet
Minecraft 1.12.2模组开发(四十三) 自定义盾牌(Shield)
MySQL数据库常识之储存引擎
41. The first missing positive number
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer
Thinkphp5 + data large screen display effect
go reflect
DeNO 1.13.2 release
2021-06-29 C escape character cancellation and use
Unity Odin ProgressBar add value column
Addition, deletion, modification and query of advanced MySQL data (DML)
C# 知识
Use 3080ti to run tensorflow GPU = 1 X version of the source code
电脑越用越慢怎么办?文件误删除恢复方法
Introduction to intrusion detection data set
On the three paradigms of database design