集合的所有分割
来源:互联网 发布:mysql攻击 编辑:程序博客网 时间:2024/05/30 04:16
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#define ALWAYS 1
void display(int *, int);
void set_partition(int n)
{
int *code, *maxi; /* arrays for code[], maxi[]*/
int i, j;
code = (int *) malloc(sizeof(int)*n); /* get memory */
maxi = (int *) malloc(sizeof(int)*n);
for (i = 0; i < n; i++) /* initialization */
code[i] = 1, maxi[i] = 2;
while (ALWAYS) { /* loop until done. */
display(code, n); /* display one partition */
for (i = n-1; code[i] == maxi[i]; i--)
; /* find next 'increasible' */
if (i > 0) { /* found ? */
code[i]++; /* YES, update */
for (j = i + 1; j < n; j++) {
code[j] = 1;
maxi[j] = maxi[i]+((code[i]==maxi[i]) ? 1 : 0);
}
}
else /* NOT FOUND, done. */
break;
}
free(code);
free(maxi);
}
/* ------------------------------------------------------ */
/* FUNCTION display : */
/* This function displays the code of the partition. */
/* ------------------------------------------------------ */
void display(int *code, int n)
{
int i;
printf("\n");
for (i = 0; i < n; i++)
printf("%3d", *(code+i));
}
/* ------------------------------------------------------ */
void main(void)
{
char line[100];
int n;
printf("\nSet Partition Program for {1,2,3,...,N}");
printf("\n=======================================");
printf("\n\nN Please --> ");
gets(line);
n = atoi(line);
printf("\nCodes of Partitions.");
printf("\ni-th position = j means i in partition j\n");
set_partition(n);
}
- 集合的所有分割
- 集合的所有分割方式
- 集合的所有分割方式
- 集合的所有分割方式---2013年1月28日
- 整数的所有分割数目
- 输出正整数的所有分割
- 求集合的分割(划分)
- 集合分割
- Palindrome Partitioning 回文串分割,求所有可能的分割
- 整数的所有不同分割数目
- 整数的所有不同分割数目
- 逗号分割的集合互转
- 打印集合所有的子集
- 打印所有可能的集合
- 求集合的所有子集
- 数组生成的所有集合
- 打印集合的所有子集
- 一个集合的所有子集
- Android 常用方法
- Node.JS学习笔记
- k个元素的子集 C(n,k)
- Oracle 8i迁移到10g注意问题
- c++流文件操作,针对string
- 集合的所有分割
- J2EE中 A项目 链接B项目 注意点
- GTK QT GNOME KDE的关系
- 整数的分割数目
- U盘无法打开的解决方法大全
- 20世纪计算机科学经典著作
- Web打印 第三方控件 Lodop
- 集群管理工具ClusterShell 安装手记
- js的悬浮效果