예제 #1
0
int main(int argc, char *argv[])
{
    char s[] = "ABCD";
    matrix_chain(s,0,9,output);
    puts(output);
    return 0;
}
예제 #2
0
int  matrix_chain(char *s, int low, int high, char **output)
{
    if (low == high)
        return 1;
    int i, j=0, n1, n2, i1, i2;

    for (i = 0; i < high - low; i++) {
        n1 = matrix_chain(s, low, low+i, s1);
        n2 = matrix_chain(s, low+i+1, high, s2);
        for (i1=0;i1<n1;i1++) {
            for(i2=0;i2<n2;i2++) {
                tmp[0]='(';
                strcat(tmp, s1[i1]);
                strcat(tmp,")(");
                strcat(tmp, s2[i2]);
                strcat(tmp,")");
                strcpy(output[j++],tmp);
            }
        }
    }
    return n1*n2;
}
예제 #3
0
파일: matrixChain.cpp 프로젝트: Gxsghsn/acm
int main()
{
    int size[100], total, i=0, m[100][100], s[100][100],j;
    memset(m,0,sizeof(m));
    memset(s,0,sizeof(s));
    memset(size,0,sizeof(size));
    printf("Please enter the number of matrix:\n");
    scanf("%d", &total);
    printf("Please enter a series of number.\nThe first number is the row of the first matrix, others are column of each matrix respectively:\n");
    while(i<=total)
        scanf("%d", &size[i++]);
    matrix_chain(size, total, m, s);
    printf("The result is:\n");
    trace_back(1, total, s);
    printf("           %d\n", m[1][total]);
    printf("\n");
    return 0;
}
예제 #4
0
int main()
{
	int *dimen_seq = NULL;
	int idx, dimen_seq_len = 0;

	scanf("%d", &dimen_seq_len);

	dimen_seq = (int *)malloc(sizeof(int)  * dimen_seq_len);
	if(!dimen_seq) {
		printf("[%s]ERROR: malloc()\n", __FUNCTION__);
		return 0;
	}

	memset(dimen_seq, 0, sizeof(int) * dimen_seq_len);

	for(idx = 0; idx < dimen_seq_len; idx += 1)
		scanf("%d", &dimen_seq[idx]);

	matrix_chain(dimen_seq, dimen_seq_len);

	free(dimen_seq);
	return 0;
}
예제 #5
0
int main() {
    int n = 0;
    scanf("%d", &n);
    matrix_chain(n);
}
예제 #6
0
int main()
{
    int p[] = {1,2,3,4}; //dimensions
    matrix_chain(p,4);
}