[BZOJ 1800] 飞行棋

Link:

BZOJ 1800 传送门

Solution:

$O(n^4)$……

Code:

#include <bits/stdc++.h>

using namespace std;
int n,pre[25],tot=0,res=0;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        pre[i]=pre[i-1]+x;tot+=x;
    }
    for(int a=1;a<=n-3;a++) for(int b=a+1;b<=n-2;b++)
    for(int c=b+1;c<=n-1;c++) for(int d=c+1;d<=n;d++)
        if(pre[b]-pre[a]==pre[d]-pre[c] && tot-(pre[d]-pre[a])==pre[c]-pre[b]) res++;
    printf("%d",res);
    return 0;
}
原文地址:https://www.cnblogs.com/newera/p/9237962.html