一道状压dp题,但是竟然可以搜索搜过!!(儒雅随和)。
代码(爆搜)
#include
using namespace std;
const double eps=1e-8;
int T,n,m,ans;
double x[25],y[25],a[25],b[25];
bool book[25];
bool cheak(double a,double b){
return (fabs(a-b)=ans) return;
if(c>n){
ans=k+clu();
return;
}
bool flag=false;
for(int i=1;i<=k;++i){
if(cheak(a[i]*x[c]*x[c]+b[i]*x[c],y[c])){
flag=true;
dfs(c+1,k);
break;
}
}
if(!flag){
for(int i=1;i<=n;++i){
if(!cheak(x[i],x[c])&&book[i]){
double a1=(x[i]*y[c]-y[i]*x[c])/(x[c]*x[i]*(x[c]-x[i]));
double b1=(y[c]-x[c]*x[c]*a1)/x[c];
if(a1<0){
a[k+1]=a1;
b[k+1]=b1;
book[i]=0;
dfs(c+1,k+1);
book[i]=1;
}
}
}
book[c]=1;
dfs(c+1,k);
book[c]=0;
}
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;++i){
scanf("%lf %lf",&x[i],&y[i]);
}
memset(book,0,sizeof(book));
ans=n;
if(m==1) ans=n/3+2;
else if(m==2) ans=(2*n)/3+1;
dfs(1,0);
printf("%d\n",ans);
}
}
状压dp
#include
using namespace std;
const double eps=1e-8;
int dp[262144],st[200],num;
double x[25],y[25];
int t,n,m;
bool cheak(double a,double b){
return fabs(a-b)