Recursive, memory Search, (checkerboard segmentation)

Source: Internet
Author: User

Topic Link http://poj.org/problem?id=1191

problem: 1191User: yinjianMemory: 568K time: 16MSLanguage: C + + Result: Accepted

Problem Solving Report:

1, the formula can be used to simplify the mathematical method, is to find the number (sum) of the sum of the squares and the smallest.

2, each division has four kinds of cases (recursion).

3, each time the location of the division to be compared, so as to find the best.

#include <stdio.h>#include<math.h>#include<algorithm>#include<string.h>using namespacestd;ints[9][9];//the score of each latticeintsum[9][9];//(i,j) to a rectangular fraction of (intres[ the][9][9][9][9];//Fun 's record sheetintCalsum (intX1,intY1,intX2,inty2)//(X1,y1) to (x2,y2) the rectangle fraction and{    returnSum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];}intFunintNintX1,intY1,intX2,inty2)//with (X1,Y1) as the upper-left corner, (x2,y2) is the bottom right corner of the rectangular checkerboard divided into n minutes after the smallest sum{    intt,a,b,c,e; intmin=0x3f3f3f3f; if(res[n][x1][y1][x2][y2]!=-1)        returnRes[n][x1][y1][x2][y2]; if(n==1) {T=calsum (X1,Y1,X2,Y2); Res[n][x1][y1][x2][y2]=t*T; returnt*T; }     for(a=x1;a<x2;a++) {C=calsum (A +1, y1,x2,y2);//The and of the Matrix on the rightE=calsum (X1,Y1,A,Y2);//The and of the left MatrixT=min (N-1, X1,y1,a,y2) +c*c,fun (n1, A +1, Y1,x2,y2) +e*e); if(min>t) min=T; }     for(b=y1;b<y2;b++) {C=calsum (x1,b+1, x2,y2);//The following matrix and theE=calsum (X1,Y1,X2,B);//The and of the matrix aboveT=min (N-1, x1,y1,x2,b) +c*c,fun (n1, x1,b+1, X2,y2) +e*e); if(min>t) min=T; } Res[n][x1][y1][x2][y2]=MIN; returnMIN;}intMain () {memset (sum,0,sizeof(sum)); memset (Res,-1,sizeof(res)); intN; scanf ("%d",&N);  for(intI=1;i<9; i++)    {         for(intj=1, rowsum=0;j<9; j + +) {scanf ("%d",&S[i][j]); Rowsum=rowsum+S[i][j]; SUM[I][J]=sum[i-1][j]+rowsum; }    }    DoubleResult=n*fun (N,1,1,8,8)-sum[8][8]*sum[8][8]; printf ("%.3f\n", sqrt (result/(nn))) ; return 0;}

Recursive, memory Search, (checkerboard segmentation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.