记录编号 |
146160 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
[HNOI 2008]明明的烦恼 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.060 s |
提交时间 |
2015-01-12 21:37:07 |
内存使用 |
0.43 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
#define Clear(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x3fffffff;
//==============struct declaration==============
struct bign{
const static int BASE=10000;
int num[5100],length;
bign(int number=0){
memset(num,0,sizeof(num));
length=0;
while (number!=0){
num[++length]=number%BASE;
number/=BASE;
}
}
bign operator *(const bign &A) const{
bign res=0;
for(int i=1;i<=length;i++)
for(int j=1;j<=A.length;j++)
res.num[i+j-1]+=num[i]*A.num[j];
for(int i=1;i<=length+A.length;i++){
res.num[i+1]+=res.num[i]/BASE;
res.num[i]%=BASE;
}
res.length=length+A.length;
while (res.length>1&&res.num[res.length]==0) res.length--;
return res;
}
bign operator *(const int &A) const{
bign temp=A;
return temp*(*this);
}
void print(){
while (length>0&&num[length]==0)
length--;
printf("%d",num[length]);
for(int i=length-1;i>=1;i--)
printf("%04d",num[i]);
printf("\n");
}
};
//==============var declaration=================
const int MAXN=10100;
int deg[MAXN],n,upn=0,downn=0,Free=0;
int up[MAXN],down[MAXN];
//==============function declaration============
int gcd(int a,int b){return a%b==0?b:gcd(b,a%b);}
//==============main code=======================
int main()
{
freopen("bzoj_1005.in","r",stdin);
freopen("bzoj_1005.out","w",stdout);
scanf("%d",&n);
if (n==1) {
int d;cin>>d;
if (d==0||d==-1)
printf("1\n");
else printf("0\n");
return 0;
}
for(int i=1;i<=n;i++){
scanf("%d",deg+i);
if (deg[i]==-1){
Free++;
continue;
}
else{
upn+=deg[i]-1;
if (upn>n-2||deg[i]==0){
printf("0\n");
return 0;
}
for(int j=2;j<deg[i];j++)
down[++downn]=j;
}
}
for(int i=1;i<=upn;i++)
up[i]=n-2-i+1;
//预处理 分子分母
for(int D=1;D<=downn;D++){
for(int U=1;U<=upn&&down[D]!=1;U++){
int G=gcd(down[D],up[U]);
down[D]/=G;up[U]/=G;
}
if (down[D]!=1){
printf("0\n");
return 0;
}//不能满足要求
}
//约分
bign res=1;
for(int i=1;i<=upn;i++)
res=res*up[i];
for(int i=upn+1;i<=n-2;i++)
res=res*Free;
//计算
res.print();
return 0;
}
//================fuction code====================