There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is Ai.
Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 109+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
Constraints
1≤N≤105
0≤Ai≤N?1
Print the number of the possible orders in which they were standing, modulo 109+7.
There are four possible orders, as follows:
·2,1,4,5,3
·2,5,4,1,3
·3,1,4,5,2
·3,5,4,1,2
#include <iostream>
#include <cstdio>
using namespace std;
int a[100005]= {0};
int n;
int pd1()
{
for(int i=1; i<=n-1; i+=2)
{
if(a[i]!=2)
{
return 0;
}
}
return 1;
}
int pd2()
{
if(a[0]!=1)
return 0;
int t = n/2;
for(int i=1; i<=t; i++)
{
if(a[i*2]!=2)
{
return 0;
}
}
return 1;
}
int main()
{
scanf("%d",&n);
for(int i=0; i<n; i++)
{
int x;
scanf("%d",&x);
a[x]++;
}
if(n%2==0)
{
int flag = pd1();
if(flag==0)
printf("0");
else
{
long long int t = 1;
int p = n/2;
for(int i=0; i<p; i++)
{
t*=2;
t%=1000000007;
}
printf("%lld",t);
}
}
else
{
int flag = pd2();
if(flag==0)
printf("0");
else
{
long long int t = 1;
int p = n/2;
for(int i=0; i<p; i++)
{
t*=2;
t%=1000000007;
}
printf("%lld",t);
}
}
}
规律题 奇数偶数分情况讨论
样例
7
6 4 0 2 4 0 2 输出:0;
8
7 5 1 1 7 3 5 3 输出:16;