算法-递归-中心对称数
namespace ZXDC; public class ZXDCS{ /// <summary> /// 前n位有多少中心对称数 /// n=1 1 8 0 /// n=2 11 69 96 88 /// </summary> public static void Show() { var zt = ZXDCDFS(4,4); System.Console.WriteLine(string.Join("-",zt)); foreach(var item in zt) { System.Console.WriteLine(string.Join("-",item)); } } public static IList<string> ZXDCDFS(int n,int m){ if(n <= 0) return new List<string>(){""}; if(n == 1) return new List<string>(){"1","0","8"}; var rtList = ZXDCDFS(n-2,m); if(m != n) rtList.Add("00"); var rtNew = new List<string>(); for(int i =0;i<rtList.Count;i++) { rtNew.Add("1"+ rtList[i] + "1"); rtNew.Add("8"+ rtList[i] + "8"); rtNew.Add("6"+ rtList[i] + "9"); rtNew.Add("9"+ rtList[i] + "6"); } return rtNew; } }
247力扣