알고리즘 기초 (Foundation of Algorithms) 5판, 5장 연습문제(1)
- 최초 등록일
- 2021.06.24
- 최종 저작일
- 2021.06
- 5페이지/ 한컴오피스
- 가격 1,500원
* 본 문서(hwp)가 작성된 한글 프로그램 버전보다 낮은 한글 프로그램에서 열람할 경우 문서가 올바르게 표시되지 않을 수 있습니다.
이 경우에는 최신패치가 되어 있는 2010 이상 버전이나 한글뷰어에서 확인해 주시기 바랍니다.
목차
없음
본문내용
11) 알고리즘 5.3(n-여왕말 문제를 푸는 되추적 알고리즘에 대한 몬테칼로 추정치 구하기)을 구현하는 프로그램을 작성하고, n=8인 문제 사례에 20번 실행시켜서 20개 추정치의 평균을 구하시오.
#include <stdio.h >
#include <malloc.h >
#include <math.h >
#include <stdlib.h >
#include <time.h >
int promising(int i, int col[]);
int estimate_n_queens(int n, int col[]) {
int i, j, z, m, mprod, numnodes;
int prom_children[n +1];
int index =0;
int flag =0;
i =0;
numnodes =1;
m =1;
mprod =1;
while (m !=0 && i !=n) {
mprod = mprod * m;
numnodes = numnodes + mprod * n;
i++;
m =0;
for (z =1; z <= n; z ++)
prom_children[z] =0;
for (j =1; j <= n; j ++) {
col[i] = j;
if (promising(i, col)) {
m++;
for (z =1; z <= n; z ++) {
if (prom_children[z] ==0) {
prom_children[z] = j;
break;
참고 자료
없음