malloc으로 하라해서 했는데 시발 malloc으로는 이차원배열 표현 못하는줄알고 일차원배열 만들어서 진짜 개노다가했다
아..시발 
int** table

for(a=0; a<n; a++)
        table[b]=(int*)malloc(sizeof(int));

이딴식으로하면 이차원배열로 사용이 가능하다니 ㅅㄴ알머ㅣㅏㄴㅇㄹ

존나 간단한 문제를 이렇게 좆같이 풀었다..

#include <stdio.h>
#include <stdlib.h>

void front(int* table, int h, int y, int value, int c);
void frontj(int* table, int h, int y, int value, int c);
void back(int* table, int h, int y, int value, int c);
void backj(int* table, int h, int y, int value, int c);

int main()
{
 int h, y;
        int *table;
        int a=0, b;
        printf("ok");
        scanf("%d %d", &h, &y);
        table=(int *)malloc(h*y*sizeof(int));
                for(a=0;a<h*y;a++)
                        table[a]=0;


        for(a=0;a<y;a++)
                table[a]=a+1;


        front(table, h, y, 1, 0);

                        for(a=0;a<h*y;a++)
                        {
                                static int c=1;
                                printf("%d ",table[a]);
                                if((a+1)%y == 0)
                                        printf("\n");
                        }

        free(table);
                return 0;
}

void front(int* table, int h, int y, int value, int c)
{
        int a;
        static int count=1;
        if(count==1 && table[c+y] == 0)
        {
                while(table[c]!=0)
                {
                table[c] = value;
                c++;
                                value++;
                }
        }
        else
        {
                while(table[c]==0)
                {
                    table[c] = value;
                    c++;
                                        value++;
                 }
         }

                for(a=0; a<h*y; a++)
                {
                        if(table[a] == 0)
                        {
                        count ++;
                        c-=1;
                        frontj(table, h, y, value, c);
                        }
                }
                return;
}

void frontj(int* table, int h, int y, int value, int c)
{
        int a;
        while(table[c+y]==0)
        {
                table[c+y] = value;
                                c+=y;
                                value++;
                }

                for(a=0; a<h*y; a++)
                {
                        if(table[a] == 0)
                        {
                        value-=1;
                        back(table, h, y, value, c);         
                        }
                }
                return;
}

void back(int* table, int h, int y, int value, int c)
{
          static int count=1;
          int a;

                                value+=1;
                while(table[c-1]==0)
                {
                table[c-1] = value;
                c-=1;
                                value+=1;
                }

                for(a=0; a<h*y; a++)
                {
                        if(table[a] == 0)
                        {
                                count ++;
                                backj(table, h, y, value, c);
                        }
                }
                return;
}
void backj(int* table, int h, int y, int value, int c)
{
        int a;
        while(table[c-y]==0)
        {
                table[c-y] = value;
                                c-=y;
                                value++;
                }


                for(a=0; a<h*y; a++)
                {
                        if(table[a] == 0)
                        {
                        c+=1;
                        front(table, h, y, value, c);    
                        }
                }
                return;
}

아 내시간 아까워 시발시발 짜증나 무식이 죄지;..