using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default15 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int[] el = { 1, 2, 3, 4,5};
this.Response.Write(GetCom<int>(el, 3));
}
public string GetCom<T>(T[] el, int n)
{
string s = "";
int p = 0;
int m = el.Length;
int[] flags = new int[m];
string str = "";
for (int i = 0; i < n; i++)
{
flags[i] = 1;
}
for (int i = n; i < m; i++)
{
flags[i] = 0;
}
p = 0;
for (int i = 0; i < flags.Length; i++)
{
if (flags[i] == 1)
{
p++;
string t = "";
if (p < n)
{

这是一个使用C#编写的组合算法示例,通过遍历并处理布尔数组来生成指定长度的组合。算法首先创建一个整数数组,然后用递归方式找到所有可能的组合,最后对结果进行排序和处理。

281

被折叠的 条评论
为什么被折叠?



