Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
35036 A21μΘ_wjy 【S】T1 C++ 通过 100 495 MS 196860 KB 746 2024-11-26 13:57:08

Tests(20/20):


#include<bits/stdc++.h> // #define int long long #define ctz __builtin_ctz using namespace std; const int maxn=27; const int N=(1<<24)+7; int n; int a[maxn]; int Sum[N]; int dp[N]; signed main(){ #ifndef ONLINE_JUDGE freopen("cloud.in","r",stdin); freopen("cloud.out","w",stdout); #endif cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=n;i>=1;i--)a[i]-=a[i-1]; int U=(1<<n)-1; for(int S=1;S<=U;S++){ int x=ctz(S); Sum[S]=Sum[S^(1<<x)]+a[x+1]; int c=S; while(c){ int x=ctz(c); dp[S]=max(dp[S],dp[S^(1ll<<x)]); c^=(1ll<<x); } if(Sum[S]==0)dp[S]++; } cout<<n-dp[U]<<endl; return 0; }


测评信息: