文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>递归算法 - 高效

递归算法 - 高效

时间:2010-09-14  来源:嗯丶善解人衣

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace PersonalInterviewTest
{
    public partial class PersonalInterviewTest : Form
    {
        public PersonalInterviewTest()
        {
            InitializeComponent();
            skinEngine1.SkinFile = @"DiamondBlue.ssk";
        }
        static PersonalInterviewTest()
        {
            Values[1] = 1;
            Values[2] = 1;
        }
        private static long[] Values = new long[93];
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox2.Text == string.Empty)
                {
                    MessageBox.Show("计算的内容不能为空。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                var CirculateTime = new Stopwatch();
                long Number = long.Parse(textBox2.Text);
                CirculateTime.Start();
                System.Threading.Thread.Sleep(1);
                textBox1.Text = string.Format("第 {0} 位的结果是 {1}" + ",总耗时 {2} 毫秒。", Number.ToString(), PassToReturn(Number).ToString(), CirculateTime.ElapsedMilliseconds);
                CirculateTime.Stop();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private static long PassToReturn(long BeWorth)
        {
            if (BeWorth <= 0 || BeWorth >= 93)
            {
                throw new NotFiniteNumberException();
            }
            if (Values[BeWorth] == 0)
            {
                Values[BeWorth] = PassToReturn(BeWorth - 1) + PassToReturn(BeWorth - 2);
            }
            return Values[BeWorth];
        }
    }
}

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载