Main topic:
A two-dimensional plane has n points, a brush, brush at a time can be a line of all the points are brushed off. Ask the minimum number of brushes, you can put all the points of the state compression DP, with the memory of the search to write, need to have an optimization or will time out. ========================================================================================
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#include<queue>#include<vector>#include<map>using namespaceStd;typedefLong LongLL;#defineMax (A, B) (A>B?A:B)Const intINF = 1e9+7;Const intMAXN = -;Const intMOD =9973;intLINE[MAXN][MAXN];intdp[70000], N;structnode{intx, y;} P[MAXN];intDFS (intSTA) { if(Dp[sta]! =-1) returnDp[sta]; Dp[sta]=INF; intCNT =0; for(intI=0; i<n; i++) if((sta& (1<<i))) CNT + +; if(CNT = =0) returnDp[sta] =0; Else if(CNT <=2) returnDp[sta] =1; for(intA=0; a<n; a++) { if((sta& (1<<a)) { for(intb=a+1; b<n; b++) { if((sta& (1<<a)) = =0)Continue; intNewsta = (sta| LINE[A][B])-Line[a][b]; Dp[sta]= Min (Dp[sta], DFS (Newsta) +1); } Break;///here is the optimization } } returnDp[sta];}intMain () {intT, Lim, CAS =1; scanf ("%d", &T); while(T--) {memset (DP,-1,sizeof(DP)); memset (line,0,sizeof(line)); scanf ("%d",&N); for(intI=0; i<n; i++) scanf ("%d%d", &p[i].x, &p[i].y); for(intI=0; i<n; i++) {Line[i][i]= (1<<i); for(intj=i+1; j<n; J + +) { for(intk=0; k<n; k++) { if((P[I].Y-P[J].Y) * (p[i].x-p[k].x) = = (P[I].Y-P[K].Y) * (p[i].x-p[j].x)) LINE[I][J]+= (1<<k); } Line[j][i]=Line[i][j]; }} dp[0] =0; Lim= (1<<n)-1; printf ("Case %d:%d\n", CAS + +, DFS (Lim)); } return 0;}
Light OJ 1018-brush (IV)