-
Notifications
You must be signed in to change notification settings - Fork 0
/
PE491.cc
60 lines (59 loc) · 1.27 KB
/
PE491.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/********************************
* Author: bigeast
* Time: 2014-12-07
* Description: AC. answer is 194505988824000.
* 搞了好久。开始是用二进制求的,后来才意识到应该用三进制。
********************************/
#include <cstdio>
#include <cstring>
#include <cassert>
#define E3_10 59049
int main(int argc, const char *argv[])
{
long long factorial[11]={1};
int dig[10];
long long res = 0;
for (int i = 1; i < 11; i++) {
factorial[i] = factorial[i-1] * i;
printf("%lld\n",factorial[i]);
}
int ver = 0;
for(int i=1,j,t,sum1,cnt,dup;i<E3_10;++i)
{
t = i;
sum1 = 0;
cnt = 0;
dup = 0;
j = 0;
memset(dig,0,sizeof(dig));
while(t)
{
dig[j] = t%3;
sum1 += dig[j]*j;
cnt += dig[j];
if(dig[j]==2)dup++;
t /= 3;
++j;
}
if(cnt != 10){
continue;
}
/*
if(sum1 == 23 || sum1 == 34 || sum1 == 45 || sum1 == 67 || sum1 == 56)
{
res += (((10-dig[0])*factorial[9])>>dup) * (factorial[10]>>dup);
}
*/
if(sum1 == 23 || sum1 == 34)
{
res += (((10-dig[0])*factorial[9])>>dup) * (factorial[10]>>dup);
t = 2 - dig[0];
res += (((10-t)*factorial[9])>>dup) * (factorial[10]>>dup);
}
else if(sum1 == 45){
res += (((10-dig[0])*factorial[9])>>dup) * (factorial[10]>>dup);
}
}
printf("%lld\n",res);
return 0;
}