当前位置:网站首页>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
边栏推荐
- 居家第二十三天的午饭
- Google tries to use rust in Chrome
- Unity ECS dots notes
- ubutnu20安裝CenterNet
- pytorch 1.7. The model saved by X training cannot be loaded in version 1.4 or earlier
- Awk example skills
- UKFslam
- 常用60类图表使用场景、制作工具推荐
- Pytorch selects the first k maximum (minimum) values and their indexes in the data
- [SQL] string series 2: split a string into multiple lines according to specific characters
猜你喜欢
Unity animation creates sequence frame code and generates animationclip
41. The first missing positive number
Amazon and epic will be settled, and the Microsoft application mall will be opened to third parties
Summary and effect analysis of methods for calculating binocular parallax
Google 尝试在 Chrome 中使用 Rust
又一款数据分析神器:Polars 真的很强大
flomo软件推荐
MySQL进阶之数据的增删改查(DML)
Common problems in deploying projects with laravel and composer for PHP
随机推荐
Is rust more suitable for less experienced programmers?
2021-06-29 C escape character cancellation and use
Explore ASP Net core read request The correct way of body
Common problems in deploying projects with laravel and composer for PHP
Selenium 显示等待WebDriverWait
Singleton mode
Amazon and epic will be settled, and the Microsoft application mall will be opened to third parties
Express③(使用Express编写接口、跨域有关问题)
3-5通过XSS获取cookie以及XSS后台管理系统的使用
【SDU Chart Team - Core】SVG属性类设计之枚举
What about laptop Caton? Teach you to reinstall the system with one click to "revive" the computer
Chrome 94 引入具有争议的 Idle Detection API,苹果和Mozilla反对
C knowledge
Learn to C language fourth day
Summary and effect analysis of methods for calculating binocular parallax
The more you use the computer, the slower it will be? Recovery method of file accidental deletion
Is qiniu school useful and is the recommended securities account safe
阿里云回应用户注册信息泄露事件
Thinking after learning to type
管道和xargs