啊啊啊我要疯了!!!tmd这么水的题目我居然因为一个地方打错调了半个小时,我是不是傻逼啊。
#include<cstdio>
#include<algorithm>
#include<cstring>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=25;
typedef long long ll;
int n,m;
int ans;
int vis[N];
int a[N];
ll mp[N][N];
inline void solve()
{
static int b[5];
int tot=0;
fo(i,1,20)if (vis[i])b[++tot]=i;
if(tot!=4)return;
if (mp[b[1]][b[2]]==mp[b[3]][b[4]]&&mp[b[2]][b[3]]==mp[b[1]][b[4]])ans++;
}
inline void dfs(int x,int dep)
{
if (dep==4||x==n+1)
{
solve();
return;
}
dfs(x+1,dep);
vis[x]=1;
dfs(x+1,dep+1);
vis[x]=0;
}
int main()
{
scanf("%d",&n);
ll sum=0;
fo(i,1,n)scanf("%d",&a[i]),sum+=a[i];
fo(i,1,n)
{
fo(j,i+1,n)
{
ll tmp=0;
fo(k,i,j-1)tmp+=a[k];
mp[i][j]=min(tmp,sum-tmp);
mp[j][i]=mp[i][j];
}
}
/*fo(i,1,n)
{
fo(j,1,n)printf("%lld ",mp[i][j]);
printf("\n");
}*/
dfs(1,0);
printf("%d\n",ans);
return 0;
}