当前位置:网站首页>C#,打印漂亮的贝尔三角形(Bell Triangle)的源程序
C#,打印漂亮的贝尔三角形(Bell Triangle)的源程序
2022-04-23 20:49:00 【深度混淆】
以贝尔数为基础,参考杨辉三角形,也可以生成贝尔三角形(Bell triangle),也称为艾特肯阵列(Aitken's Array),皮埃斯三角形(Peirce Triangle)。
贝尔三角形的构造方法:
(1)第一行第一个元素是1,即a[1][1] = 1
(2)对于n>1,第n行第一项等于第n-1行最后一项,即a[n][1] = a[n-1][n-1];
(3)对于m,n>1,第n行第m项等于它左边和左上方的两个数之和,即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)
/// 艾特肯阵列(Aitken's Array)
/// 皮埃斯三角形(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
版权声明
本文为[深度混淆]所创,转载请带上原文链接,感谢
https://blog.csdn.net/beijinghorn/article/details/124338212
边栏推荐
- Awk example skills
- Pytorch preserves different forms of pre training models
- 亚马逊和Epic将入驻,微软应用商城向第三方开放
- On IRP from the perspective of source code
- Zhongchuang storage | how to choose a useful distributed storage cloud disk
- Thinking after learning to type
- How to do after winning the new debt? Is it safe to open an account online
- Lunch on the 23rd day at home
- Reentrant function
- Bracket matching -- [implementation of one-dimensional array]
猜你喜欢
Leetcode 542, 01 matrix
Summary and effect analysis of methods for calculating binocular parallax
GO语言开发天天生鲜项目第三天 案例-新闻发布系统二
A login and exit component based on token
Come in and teach you how to solve the problem of port occupation
电脑越用越慢怎么办?文件误删除恢复方法
Addition, deletion, modification and query of MySQL advanced table
笔记本电脑卡顿怎么办?教你一键重装系统让电脑“复活”
PHP的Laravel与Composer部署项目时常见问题
Deep analysis of C language pointer (Part I)
随机推荐
Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
Leetcode 709, convert to lowercase
Introduction to intrusion detection data set
MySQL advanced common functions
常用60类图表使用场景、制作工具推荐
MySQL 存储过程和函数
Deno 1.13.2 发布
【SQL】字符串系列2:将一个字符串根据特定字符分拆成多行
韩国或将禁止苹果和谷歌向开发者抽佣 创全球首例
又一款数据分析神器:Polars 真的很强大
Sequential state
The more you use the computer, the slower it will be? Recovery method of file accidental deletion
LeetCode-279-完全平方数
Linux中,MySQL的常用命令
Bracket matching -- [implementation of one-dimensional array]
Factory mode
Awk example skills
软件测试要怎么学?自学还是培训看完这篇文章你就懂了
pytorch 1.7. The model saved by X training cannot be loaded in version 1.4 or earlier
Vulnhub DC: 1 penetration notes