按位枚举,按最小价值,最小砍掉树剪枝就好了。
#include#include #include #include #include using namespace std;const int MAXN=20;const int inf=190000000;int n,l;int st[MAXN],stop,cnt;int ans[MAXN];bool cut[MAXN];struct point{ int x,y; int len,val; int num;}p[MAXN];int ansV,ansC;double anslen;bool cmp(point A,point B){ if(A.y 1&&multi(p[st[stop-1]],p[i],p[st[stop-2]])) stop--; st[stop++]=i; } for(int i=0;i =0;i--){ if(!cut[i]){ st[stop++]=i; choice++; } if(choice==2){ be=i; break; } } for(int i=be-1;i>=0;i--){ if(cut[i]) continue; while(stop>1&&multi(p[st[stop-1]],p[i],p[st[stop-2]])) stop--; st[stop++]=i; } for(int i=0;i tmpC){ slove(); double res=for_len(); if(res<=len){ CUT=tmpC; ansV=tmpV; ansC=i; anslen=len*1.0-res; } } } } printf("Forest %d\n",cas); printf("Cut these trees:"); cnt=0; for(int k=0;k