60分代码,后几个点MLE。
#include<bits/stdc++.h>
using namespace std;
string a[1002][1002]= {"0"};
long long k,x;
long long ksm(long long a, long long b) {
long long k=1000;
long long ans,d,c;
c=a;
d=b;
ans=1%k;
while(b) {
if(b%2) {
ans=(ans*a)%k;
}
a=(a*a)%k;
b/=2;
}
return ans;
}
string cplus(string x,string y) {
int a[301]= {0},b[301]= {0};
int c[301]= {0},len=0;
string ans="";
for(int i=x.length()-1,j=1; i>=0; i--,j++) {
a[j]=x[i]-'0';
}
for(int i=y.length()-1,j=1; i>=0; i--,j++) {
b[j]=y[i]-'0';
}
if(x.length()>=y.length()) {
len=x.length();
} else {
len=y.length();
}
for(int i=1; i<=len; i++) {
c[i]+=a[i]+b[i];
c[i+1]=c[i]/10;
c[i]=c[i]%10;
}
if(c[len+1]) {
len++;
}
for(int i=len; i>=1; i--) {
ans+=c[i]+'0';
}
return ans;
}
int main() {
// freopen("title.in","r",stdin);
// freopen("title.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>k>>x;
x=ksm(x,x);
for(int i=1; i<=x+k; i++) {
for(int j=1; j<=i; j++) {
if(j==1) {
a[i][j]="1";
} else {
if(a[i-1][j-1]==""){
a[i-1][j-1]="0";
}
if(a[i-1][j]==""){
a[i-1][j]="0";
}
a[i][j]=cplus(a[i-1][j-1],a[i-1][j]);
}
}
}
cout<<a[x][k];
return 0;
}
大佬帮忙看一下,谢谢谢谢