RT,程序中的dp数组未经人为的赋值(已使用memset初始化),但是在pre函数中,随着循环,dp中的值发生了改变,这是因为啥啊
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
int n,ccf,cnt;
double fx[50],fy[50];
int pwx[100];
int dp[1<<18];
bool equal(double a,double b){
if(a-b>=eps) return false;
if(b-a>=eps) return false;
return true;
}
double fca(double x1,double y1,double x2,double y2){
return (x1*y2-x2*y1) / (x1*x2) / (x2-x1);
}
double fcb(double x1,double y1,double x2,double y2){
return (x1*x1*y2-x2*x2*y1) / (x1*x2) / (x1-x2);
}
double f(double a,double b,double x){
return a*x*x+b*x;
}
bool at_line(double a,double b,int j){
if(equal(fy[j],f(a,b,fx[j]))) return true;
return false;
}
void pre(){
for(int i=0;i<n;++i){
pwx[++cnt] = 1<<i;
printf("ccf1 %d dp[0]= %d\n",i,dp[0]);
for(int j=i+1;j<n;++j){
printf("ccf2 %d %d dp[0]= %d\n",i,j,dp[0]);
double a=fca(fx[i],fy[i],fx[j],fy[j]);
double b=fcb(fx[i],fy[i],fx[j],fy[j]);
if(a>=0) continue;
//if(!at(a,b,j)) continue;
pwx[++cnt] = 1<<i;
for(int k=j;k<n;++k){
if(!at_line(a,b,k)) continue;
pwx[cnt] |= (1<<k);
}
}
printf("ccf %d dp[0]= %d\n",i,dp[0]);
}
}
void init(){
cnt=0;
memset(pwx,0,sizeof(pwx));
memset(dp,0x7f,sizeof(dp));
dp[0] = 0;
return ;
}
int main(){
int T;
cin>>T;
while(T--){
init();
cin>>n>>ccf;
for(int i=0;i<n;++i){
cin>>fx[i]>>fy[i];
}
pre();
}
return 0;
}