1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <bits/stdc++.h> #define F(n) Fi(i,n) #define Fi(i,n) Fl(i,0,n) #define Fl(i,l,n) for(int i=(l);i<(n);i++) using namespace std; const int N = 51, MAX = 2147483647; typedef pair<int,int> PII; PII D[N]; int n,m,ans; bool wed[N]; inline PII operator-(PII a,PII b){ return PII(a.first-b.first,a.second-b.second); } inline int cross(PII a,PII b){ return a.first*b.second - b.first*a.second; } inline int triangle_area(PII a,PII b,PII c){ return abs(cross(a,b)+cross(b,c)+cross(c,a)); } void DFS(int area,int pre,int x,int k,int fs,int sd){ if(area>=ans)return; if(k>=m-1); else if(cross(D[x]-D[pre],D[fs]-D[x])<0)return; else if(cross(D[fs]-D[x],D[sd]-D[fs])<0)return; else if(k==1){ ans = min(ans,area); return; } F(n)if(!wed[i]){ if(k==m||cross(D[x]-D[pre],D[i]-D[x])>0){ wed[i]=true; int tmp = area + (k==m?0:triangle_area(D[fs],D[x],D[i])); if(k==m)sd = i; DFS(tmp,x,i,k-1,fs,sd); wed[i]=false; } } } main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>m; F(n)cin>>D[i].first>>D[i].second; ans = MAX; F(n){ wed[i] = true; DFS(0,-1,i,m,i,-1); wed[i] = false; } cout<<(ans==MAX?0:(ans>>1))<<'\n'; }
|