-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1089 [SCOI2003]严格n元树(DP+高精).cpp
67 lines (67 loc) · 1.13 KB
/
1089 [SCOI2003]严格n元树(DP+高精).cpp
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
61
62
63
64
65
66
67
#include <cstdio>
const int Len=505;
struct huge{
int len,a[Len];
friend huge operator * (const huge &a,const huge &b){
huge c;
c.len=a.len+b.len+2;
int x=0;
for(int i=0;i<c.len;i++){
for(int j=0;j<=i;j++) if(j<a.len&&i-j<b.len)
x+=a.a[j]*b.a[i-j];
c.a[i]=x%10;
x/=10;
}
while(c.len&&c.a[c.len-1]==0) c.len--;
return c;
}
friend huge operator - (const huge &a,const huge &b){
huge c;
c.len=a.len;
int x=0;
for(int i=0;i<a.len;i++){
x+=a.a[i]-(i<b.len?b.a[i]:0);
if(x<0){
c.a[i]=x+10;
x=-1;
}
else{
c.a[i]=x;
x=0;
}
}
while(c.len&&c.a[c.len-1]==0) c.len--;
return c;
}
void operator ++ () {
a[len++]=0;
int i;
for(i=0;a[i]==9;i++) a[i]=0;
a[i]++;
while(len&&a[len-1]==0) len--;
}
void print(){
if(!len){
puts("0");
return;
}
printf("%d",a[len-1]);
for(int i=len-2;i>=0;i--) printf("%d",a[i]);
puts("");
}
};
int n,d;
huge f[17];
int main(){
scanf("%d%d",&n,&d);
if(d==0) return puts("1"),0;
f[0].len=1;
f[0].a[0]=1;
for(int i=1;i<=d;i++){
f[i].len=1;
f[i].a[0]=1;
for(int j=0;j<n;j++) f[i]=f[i]*f[i-1];
++f[i];
}
(f[d]-f[d-1]).print();
}