Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
35044 | baka24 | 【S】T1 | C++ | 通过 | 100 | 1445 MS | 131380 KB | 673 | 2024-11-26 14:15:43 |
#include<bits/stdc++.h> using namespace std; int read(){int x=0,f=1;char c=getchar();while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;} const int N=24; int n,m,ans,a[N]; int f[1<<N],lg2[1<<N]; void slv(){ n=read(); for(int i=0;i<n;i++)a[i]=read(),lg2[1<<i]=i; for(int i=n-1;i>=1;i--)a[i]-=a[i-1]; for(int i=0;i<1<<n;i++){ int sum=0,tmp=i; while(tmp)sum+=a[lg2[tmp&(-tmp)]],tmp-=tmp&(-tmp); for(int j=0;j<n;j++)if(!(i&(1<<j)))f[(1<<j)|i]=max(f[i|(1<<j)],(f[i]+(sum+a[j]==0))); } printf("%d",n-f[(1<<n)-1]); } signed main(){ slv(); return 0; }