快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

顺序求出c(n,r)的排列组合

 using System;

namespace combinaton
{
 /// <summary>
 /// Summary description for Class1.
 /// </summary>
 class Class1
 {
  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   //
   // TODO: Add code to start application here
   //
   Console.WriteLine(\"please input n :\");
   long n=long.Parse(Console.ReadLine());
   Console.WriteLine(\"please input r :\");
   long r=long.Parse(Console.ReadLine());
   combinaton(n,r);
   Console.ReadLine();
  }
  static void combinaton(long n,long r)
  {
   if(n<r)
   {
    long temp;
    temp=n;
    n=r;
    r=temp;
   }
   long[] s=new long[n];
   long count = combi(n,r);
   Console.WriteLine(\"there are total:{0}count:\",count);
   for(long i=0;i<r;i++)
   {
    s[i]=i+1;
    Console.Write(\"{0}\",s[i]);
   }
   Console.WriteLine();
   for(long i=1;i<count;i++)
   {
    long m=r-1,max_value=n;
    while(s[m]==max_value)
    {
     m=m-1;
     max_value=max_value-1;
    }
    s[m]=s[m]+1;
    for(long j=m+1;j<r;j++)
    {
     s[j]=s[j-1]+1;
    }
    for(long k=0;k<r;k++)
    {
     Console.Write(\"{0}\",s[k]);
    }
    Console.WriteLine();
   }
  }

  //compute value of c(n,r)
  static long combi(long n,long r)
  {
   long sn=1,sr=1,s_r=1;
   for(long i=1;i<=n;i++)
   {
    sn*=i;
   }
   for(long j=1;j<=r;j++)
   {
    sr*=j;
   }
   for(long k=1;k<=n-r;k++)
   {
    s_r*=k;
   }
   sr*=s_r;
   return sn/sr;
  }
 }
}


返回类别: 教程
上一教程: 转标题 C#和VB.NET的区别 qianqian(原作)
下一教程: 如何在aspx中得到在存储过程中的的数值(兼答jspfuns的问题)

您可以阅读与"顺序求出c(n,r)的排列组合"相关的教程:
· 如何得到一个汉字和字母组合的字符串的正确的长度(asp.net 版本的)
    微笑服务 优质保证 索取样品