목록알고리즘 (35)
알맹이방
#include #include #include "concat.h" using namespace std; concat::concat(void){ this->num = 0; this->pa = 0; return; } concat::concat(int* priority, char **words, int n){ int i=0; this->num = n; this->pa = new pri* [n]; for(i=0;ipa[i] = new pri(priority[i], words[i]); return; } concat::~concat(void){ if(this->pa){ int i=0, n = this->num; for(i=0;ipa[i])delete this->pa[i]; delete[] this->pa; } r..
#include #include "closest.h" #if 0 DO NOT MODIFY closest(void), ~closest(void), and setPoints(point* p, int n)! #endif closest::closest(void){ this->pnt = NULL; this->num = 0; return; } closest::~closest(void){ if(this->pnt)delete this->pnt; return; } void closest::setPoints(point* p, int n){ int i=0; if(this->pnt)delete this->pnt; this->pnt = new point[n]; this->num = n; for(i=0;ipnt[i] = p[i]..
#include #include "inv.h" #define MODE 0 using namespace std; inv::inv(){ this->array = NULL; this->size = 0; } inv::~inv(){ if(this->array)delete this->array; return; } void inv::reset(int *a, int s){ int i=0; if(this->array)delete this->array; this->array = new int[s]; this->size = s; for(i=0;iarray+i) = *(a+i); return; } void inv::printArray(void){ int i = 0; for(i=0;i
n*n 격자에서 갈 수 있는 모든 경로 (돌아가는 길 포함) 경우의 수를 세는 알고리즘인데 수행시간이 너무 오래 걸린다. 5*5까지 가능함. #include "grid.h" #include using namespace std; unsigned long long grid::numOfWays(void){ int visited[10][10]={0}; visited[0][0]=1; fun(visited, 0,0); return result; } int grid::fun(int (*arr)[10], int a, int b){ if(a==n&&b==n){ result+=1; arr[a][b]=0; return 0; } if(arr[a+1][b]==0||arr[a-1][b]==0||arr[a][b-1]==0||arr..