萌新刚学状压
  • 板块P1433 吃奶酪
  • 楼主wo_hen_la
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/9/2 23:02
  • 上次更新2024/9/2 23:04:15
查看原帖
萌新刚学状压
794701
wo_hen_la楼主2024/9/2 23:02

50分WA on #1,3,5,6,9,11,12,13

#include <bits/stdc++.h>
using namespace std;

#define sp putchar(' ')
#define en putchar('\n')
#define pb push_back
#define int long long
#define P 998244353
#define HP 1000000000000002097
#define N (int)(2e5+5)

int read(){ char ch=getchar();int x=0,f=1;while(ch>'9' || ch<'0'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();return x*f; }
void print(int x){ if(x<0) putchar('-'),x=-x;if(x>9)print(x/10);putchar(x%10+'0'); }

int n;
double x[N],y[N],dp[17][1<<17];
double dis(int i,int j)
{
	return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));;
}
signed main()
{
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>y[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<(1<<n);j++) dp[i][j]=1e9;
	}
	for(int i=1;i<=n;i++) dp[i][1<<(i-1)]=dis(0,i);
	for(int st=0;st<(1<<n);st++){
		for(int i=1;i<=n;i++){
			if(!( (st>>(i-1))&1 )) continue;
			int x=st-(1<<(i-1)),cnt=0;
			while(x){
				cnt++;
				if(x%2==1) dp[i][st]=min(dp[i][st],dp[cnt][st-(1<<(i-1))]+dis(cnt,i));
				x>>=1;
			}
		}
	}
	printf("%.2lf",dp[n][(1<<n)-1]);
	return 0;
}
2024/9/2 23:02
加载中...