ëŠ�ë‚€ì � ë°� 설명 ¶
ì�Œ.. ì €ë²ˆ 것과 마찬가지로 ìž…ë ¥ë°›ëŠ” 부분ì�€ 시간계산ì—� í�¬í•¨í•˜ì§€ 않는다. (사용ìž�ì�˜ ìž…ë ¥ì‹œê°„ì�´ ê²°ì •í•˜ê¸° 때문.)
�한 오버헤드를 줄�다는 명목하� 함수로 나누지� 않았따. (귀차니즘.ㅎ)
ì•„ìš°.. 27시간 ë�™ì•ˆ 깨있었ë�”니 ì£½ê² ... ì�¸ìƒ�태ì—�서 만들어 졌으며, 그래서 소스가 ì§€ì €ë¶„ í• ìˆ˜ 있다.
ì•Œê³ ë¦¬ì¦˜ì�€ 1ê³¼ 0으로 수를 ì €ìž¥, 한칸씩 옮겨가면서 ëª¨ë“ ê²½ìš°ì�˜ 수를 찾는 것ì�´ë‹¤.
�한 예를 들어 7개� 경우는 1개�때, 2개�때, ... 7개�때 �런�으로 나누어서 연산� 한다.
ì�Œ ì˜�í˜¸ì„ ë°°ì�˜ 페ì�´ì§€ë¥¼ 보니 ì�´ 페ì�´ì§€ì�˜ 설명ì�´ 부족한듯 해서 ë�§ë¶™ì�¸ë‹¤.
예를 들어 9Set� 하면..
ë°°ì—´1 - 1,2,3,4,5,6,7,8,9
ë°°ì—´2 - 1 0 0 0 0 0 0 0 0
ì�´ë ‡ê²Œ 세팅후 1ì�¸ 경우ì—� ì¶œë ¥í•œë‹¤. 한차례연산후
ë°°ì—´2 - 0 1 0 0 0 0 0 0 0
ë°°ì—´2 - 0 0 1 0 0 0 0 0 0
ë°°ì—´2 - 0 0 0 1 0 0 0 0 0
ë°°ì—´2 - 0 0 0 0 1 0 0 0 0
ë°°ì—´2 - 0 0 0 0 0 1 0 0 0
ë°°ì—´2 - 0 0 0 0 0 0 1 0 0
ë°°ì—´2 - 0 0 0 0 0 0 0 1 0
ë°°ì—´2 - 0 0 0 0 0 0 0 0 1
�런�� 연산� 거치게 �다.
그후 2개로 �가시켜서 계산...�한 오버헤드를 줄�다는 명목하� 함수로 나누지� 않았따. (귀차니즘.ㅎ)
ì•„ìš°.. 27시간 ë�™ì•ˆ 깨있었ë�”니 ì£½ê² ... ì�¸ìƒ�태ì—�서 만들어 졌으며, 그래서 소스가 ì§€ì €ë¶„ í• ìˆ˜ 있다.
ì•Œê³ ë¦¬ì¦˜ì�€ 1ê³¼ 0으로 수를 ì €ìž¥, 한칸씩 옮겨가면서 ëª¨ë“ ê²½ìš°ì�˜ 수를 찾는 것ì�´ë‹¤.
�한 예를 들어 7개� 경우는 1개�때, 2개�때, ... 7개�때 �런�으로 나누어서 연산� 한다.
| 숫�� 수 | 걸리는 시간(초) |
| 9개 | 0.078 |
| 10개 | 0.172 |
| 11개 | 0.375 |
| 12개 | 0.781 |
예를 들어 9Set� 하면..
ë°°ì—´1 - 1,2,3,4,5,6,7,8,9
ë°°ì—´2 - 1 0 0 0 0 0 0 0 0
ì�´ë ‡ê²Œ 세팅후 1ì�¸ 경우ì—� ì¶œë ¥í•œë‹¤. 한차례연산후
ë°°ì—´2 - 0 1 0 0 0 0 0 0 0
ë°°ì—´2 - 0 0 1 0 0 0 0 0 0
ë°°ì—´2 - 0 0 0 1 0 0 0 0 0
ë°°ì—´2 - 0 0 0 0 1 0 0 0 0
ë°°ì—´2 - 0 0 0 0 0 1 0 0 0
ë°°ì—´2 - 0 0 0 0 0 0 1 0 0
ë°°ì—´2 - 0 0 0 0 0 0 0 1 0
ë°°ì—´2 - 0 0 0 0 0 0 0 0 1
�런�� 연산� 거치게 �다.
ë°°ì—´2 - 1 1 0 0 0 0 0 0 0
ë°°ì—´2 - 1 0 1 0 0 0 0 0 0
ë°°ì—´2 - 1 0 0 1 0 0 0 0 0
ë°°ì—´2 - 1 0 0 0 1 0 0 0 0
ë°°ì—´2 - 1 0 0 0 0 1 0 0 0
ë°°ì—´2 - 1 0 0 0 0 0 1 0 0
ë°°ì—´2 - 1 0 0 0 0 0 0 1 0
ë°°ì—´2 - 1 0 0 0 0 0 0 0 1
ë°°ì—´2 - 0 1 1 0 0 0 0 0 0
ë°°ì—´2 - 0 1 0 1 0 0 0 0 0
ë°°ì—´2 - 0 1 0 0 1 0 0 0 0
ë°°ì—´2 - 0 1 0 0 0 1 0 0 0
ë°°ì—´2 - 0 1 0 0 0 0 1 0 0
ë°°ì—´2 - 0 1 0 0 0 0 0 1 0
ë°°ì—´2 - 0 1 0 0 0 0 0 0 1
ë°°ì—´2 - 0 0 1 1 0 0 0 0 0
.
.
(후략)
ì�´ëŸ°ì‹�으로 ì—°ì‚°ì�„ 하여 ëª¨ë“ ê²½ìš°ì�˜ 수를 찾아낸다.^^
질문ì�´ë‚˜ 부족한 ì �ì—� 대해서는 글ì�„ 남겨주세요.^^*
ë°°ì—´2 - 1 0 1 0 0 0 0 0 0
ë°°ì—´2 - 1 0 0 1 0 0 0 0 0
ë°°ì—´2 - 1 0 0 0 1 0 0 0 0
ë°°ì—´2 - 1 0 0 0 0 1 0 0 0
ë°°ì—´2 - 1 0 0 0 0 0 1 0 0
ë°°ì—´2 - 1 0 0 0 0 0 0 1 0
ë°°ì—´2 - 1 0 0 0 0 0 0 0 1
ë°°ì—´2 - 0 1 1 0 0 0 0 0 0
ë°°ì—´2 - 0 1 0 1 0 0 0 0 0
ë°°ì—´2 - 0 1 0 0 1 0 0 0 0
ë°°ì—´2 - 0 1 0 0 0 1 0 0 0
ë°°ì—´2 - 0 1 0 0 0 0 1 0 0
ë°°ì—´2 - 0 1 0 0 0 0 0 1 0
ë°°ì—´2 - 0 1 0 0 0 0 0 0 1
ë°°ì—´2 - 0 0 1 1 0 0 0 0 0
.
.
(후략)
ì�´ëŸ°ì‹�으로 ì—°ì‚°ì�„ 하여 ëª¨ë“ ê²½ìš°ì�˜ 수를 찾아낸다.^^
질문ì�´ë‚˜ 부족한 ì �ì—� 대해서는 글ì�„ 남겨주세요.^^*
소스 ¶
~cpp
#include <time.h>
#include <stdio.h>
#include <iostream>
int* input_and_return_number(int*);
void process(int*, int);
int main()
{
int time_in; // 초기 시작 시간.
/////
int gaesu;
int *temp_gaesu=&gaesu;
int *numbers=input_and_return_number(&gaesu);
/////
time_in = clock(); // 초기 시작 시간ì�„ ìž…ë ¥í•œë‹¤.
process(numbers,gaesu);
free(numbers);
printf("CPU CLOCKS = %d\n", clock() - time_in); // �났�때 시간 - 초기 시작시간 = 프로그램 실행 시간
return 0; // 프로그램 종료.
}
int* input_and_return_number(int *number_gaesu)
{
printf("ìž…ë ¥í• ìˆ«ìž�ì�˜ 개수는?>>");
fflush(stdin);
scanf ("%d",number_gaesu);
int *numbers=(int*)malloc(sizeof(int)*(*number_gaesu));
for (register int i=0; i<*number_gaesu; ++i)
{
printf("%d번째ì�˜ 숫ìž�를 ìž…ë ¥í•´ì£¼ì„¸ìš”.>>",i+1);
fflush(stdin);
scanf("%d",numbers+i);
}
return numbers;
}
void process(int *numbers, int gaesu)
{
int *temp_where=(int*)malloc(sizeof(int)*gaesu);
for (register int temp_gaesu=1; temp_gaesu<=gaesu; ++temp_gaesu)
{
int bun_ja=1;
int bun_mo=1;
for (register int i=0; i<temp_gaesu; ++i)
{
bun_ja*=gaesu-i;
bun_mo*=i+1;
}
int combination=bun_ja/bun_mo;
for (register int i=0; i<gaesu; ++i)
{
if (i<temp_gaesu)
temp_where[i]=1;
else
temp_where[i]=0;
}
for (register int i=0; i<combination; ++i)
{
printf("{");
int end=gaesu-1;
for (register int j=0; j<gaesu; ++j)
{
if(1==temp_where[j])
printf(" %d ",numbers[j]);
}
printf("} ");
int find_last=end;
for (; find_last>=0; --find_last)
{
if (1==temp_where[find_last])
break;
}
if (find_last==end)
{
int gaesu_of_one=0;
int find_zero=0;
for (register int j=end; j>=0; --j)
{
if (0==temp_where[j])
find_zero=1;
else
{
temp_where[j]=0;
if (0==find_zero)
++gaesu_of_one;
else
{
for (register int k=j+1; k<j+2+gaesu_of_one; ++k )
temp_where[k]=1;
break;
}
}
}
}
else
{
temp_where[find_last]=0;
temp_where[find_last+1]=1;
}
}
}
free(temp_where);
}










