bzoj 1005 1211 1867
parent
75440536c2
commit
0145e378f0
@ -0,0 +1,41 @@
|
||||
def fast_pow(a,b):
|
||||
ans=1
|
||||
while b:
|
||||
if(b%2==1):
|
||||
ans*=a
|
||||
a*=a
|
||||
b/=2
|
||||
return ans
|
||||
frac=[1]
|
||||
for i in range(1,1001):
|
||||
frac.append(i*frac[-1])
|
||||
n=(int)(input())
|
||||
m=0
|
||||
arr=[]
|
||||
for i in range(0,n):
|
||||
arr.append((int)(input()))
|
||||
ans=0
|
||||
if n==1:
|
||||
if arr[0]==0:
|
||||
ans=1
|
||||
else:
|
||||
ans=0
|
||||
else:
|
||||
ans=frac[n-2]
|
||||
left=n-2
|
||||
for i in arr:
|
||||
if i == -1:
|
||||
m+=1
|
||||
elif i==0:
|
||||
ans=0
|
||||
left=0
|
||||
break
|
||||
else:
|
||||
ans/=frac[i-1]
|
||||
left-=i-1
|
||||
if m<2:
|
||||
ans=0
|
||||
else:
|
||||
ans/=frac[left]
|
||||
ans*=fast_pow(m,left)
|
||||
print ans
|
||||
@ -0,0 +1,66 @@
|
||||
#include <cstdio>
|
||||
typedef long long int64;
|
||||
int prime[201], pcnt, cnt[201];
|
||||
bool notprime[1001];
|
||||
void genPrime()
|
||||
{
|
||||
notprime[0] = notprime[1] = true;
|
||||
for (int i = 2; i < 1001; i++)
|
||||
if (!notprime[i])
|
||||
for (int j = i*i; j < 1001; j += i)
|
||||
notprime[j] = true;
|
||||
for (int i = 0; i < 1001; i++)
|
||||
if (!notprime[i])
|
||||
prime[pcnt++] = i;
|
||||
}
|
||||
int64 fast_pow(int64 x, int y)
|
||||
{
|
||||
int64 ans = 1;
|
||||
for (; y; x *= x, y >>= 1)
|
||||
if (y & 1)
|
||||
ans *= x;
|
||||
return ans;
|
||||
}
|
||||
void decomp(int x, int d)
|
||||
{
|
||||
for (int i = 0; i < pcnt && x; i++)
|
||||
while (x % prime[i] == 0)
|
||||
{
|
||||
cnt[i] += d;
|
||||
x /= prime[i];
|
||||
}
|
||||
}
|
||||
int64 comp()
|
||||
{
|
||||
int64 ans = 1;
|
||||
for (int i = 0; i < pcnt; i++)
|
||||
if (cnt[i])
|
||||
ans *= fast_pow(prime[i], cnt[i]);
|
||||
return ans;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
genPrime();
|
||||
int n, sum = 0;
|
||||
scanf("%d", &n);
|
||||
if (n == 1)
|
||||
{
|
||||
scanf("%d", &n);
|
||||
putchar('0' + !n);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 2; i <= n - 2; i++)
|
||||
decomp(i, 1);
|
||||
for (int i = 0, x; i < n; i++)
|
||||
{
|
||||
scanf("%d", &x);
|
||||
if (x == 0) break;
|
||||
sum += x - 1;
|
||||
for (int j = 2; j < x; j++)
|
||||
decomp(j, -1);
|
||||
}
|
||||
printf("%lld", sum != n - 2 ? 0 : comp());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
typedef unsigned long long int64;
|
||||
inline int64 gcd(int64 a, int64 b)
|
||||
{
|
||||
int64 tmp;
|
||||
if (a < b) { tmp = a; a = b; b = tmp; } //make sure a>b
|
||||
while (b)
|
||||
{
|
||||
tmp = b;
|
||||
b = a%b;
|
||||
a = tmp;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
int64 a[51][51];
|
||||
char c[51][51];
|
||||
int n, m;
|
||||
|
||||
void calc(int i, int j)
|
||||
{
|
||||
if (j > i || i >= n) return;
|
||||
else
|
||||
{
|
||||
if (c[i][j] == '*')
|
||||
{
|
||||
a[i + 1][j] += (a[i][j] / 2);
|
||||
a[i + 1][j + 1] += (a[i][j] / 2);
|
||||
}
|
||||
else if (c[i][j] == '.')
|
||||
{
|
||||
a[i + 2][j + 1] += a[i][j];
|
||||
}
|
||||
else return;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
scanf("%d%d", &n, &m);
|
||||
int64 total = (1ULL << n);
|
||||
for (int i = 0; i < n; i++)
|
||||
for (int j = 0; j <= i; j++)
|
||||
std::cin >> c[i][j];
|
||||
a[0][0] = total;
|
||||
for (int i = 0; i < n; i++)
|
||||
for (int j = 0; j <= i; j++)
|
||||
calc(i, j);
|
||||
int64 k = gcd(a[n][m], total);
|
||||
printf("%lld/%lld", a[n][m] / k, total / k);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in new issue