Light OJ 1018-brush (IV)

Source: Internet
Author: User

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&GT;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)

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.