由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 一个简单的算法问题?
相关主题
c++ template中如何判断类型大家帮我看看这个C程序为什么出错了
IDL一问Static variables in function
请看看这个Perl random sampling code 有什么问题,tree data conversion
这个怎么allocate memory?How to have another func call printf with va_arg list ?
c的问题(2)10个包子请教一个简单的编程问题
[合集] 为什么不能: declare a static memeber func这个函数有问题吗?
[合集] C问题求助:如何强行从外部访问local static variable?A question about singleton
func调用结束时出错也问个二维数组的函数传递问题
相关话题的讨论汇总
话题: int话题: arr话题: array话题: 1xm话题: static
进入Programming版参与讨论
1 (共1页)
w****j
发帖数: 237
1
请问,如果一个 NxM 的 array, 想组成一组 1xM 的数列,其中的元素是从对应array
M 列中抽出,则一共有 N^M 组 的 1xM 数列,请问如果想穷具所有的 1xM 数列,应该
如何实现?
example: 2x2 array: [a11, a12; a21, a22]
4 possible rows: [a11, a12], [a11,a22], [a21,a12], [a21,a22]
How to realize in C or MATLAB?
先谢了
k*k
发帖数: 508
2
========================
int M=xxx;
int N=yyy;
void print_result(int* arr)
{
int i;

for (i=0;i printf("%d ", arr[M]);
printf("\n");
}
void perm(int* arr, int k)
{
int i;
for (i=0;i {
arr[k]=data[i][k];
if (k perm(arr, k+1)
else
print_result(arr);
}
}
int main()
{
// initialize data array (N*M)
.....
int *arr;
arr=(int*)malloc(M*sizeof(int));
perm(arr, 0

【在 w****j 的大作中提到】
: 请问,如果一个 NxM 的 array, 想组成一组 1xM 的数列,其中的元素是从对应array
: M 列中抽出,则一共有 N^M 组 的 1xM 数列,请问如果想穷具所有的 1xM 数列,应该
: 如何实现?
: example: 2x2 array: [a11, a12; a21, a22]
: 4 possible rows: [a11, a12], [a11,a22], [a21,a12], [a21,a22]
: How to realize in C or MATLAB?
: 先谢了

w****j
发帖数: 237
3
hehe, thanks very much for your help
w****p
发帖数: 18
4
Please see my Java code for this problem:
public class Main {

static int M; static int N;
/* example here. You can replace to your own array */
/* works for arbitrary dimension array */
static int[][] myarray = {{1,2,3}, {4,5,6},{7,8,9},{10,11,12}};
public static void main(String[] args) {
// TODO code application logic here
N=myarray.length;
M=myarray[0].length;
int[] tt=new int[M];
Func(0,tt);
}

static void Func(int k,
1 (共1页)
进入Programming版参与讨论
相关主题
也问个二维数组的函数传递问题c的问题(2)
golang的method是后来加的?[合集] 为什么不能: declare a static memeber func
C++ question[合集] C问题求助:如何强行从外部访问local static variable?
JHQ的一道指针题。func调用结束时出错
c++ template中如何判断类型大家帮我看看这个C程序为什么出错了
IDL一问Static variables in function
请看看这个Perl random sampling code 有什么问题,tree data conversion
这个怎么allocate memory?How to have another func call printf with va_arg list ?
相关话题的讨论汇总
话题: int话题: arr话题: array话题: 1xm话题: static