完了,高精超时了!
查看原帖
完了,高精超时了!
658786
STUDENT00楼主2022/9/16 22:16

代码如下:

#include<bits/stdc++.h>
using namespace std;
int n,m;
string dp[110][110]; 
string pro(string a,int b){
	int c[110]={0},len=a.length(),w=len;
	for(int i=0;i<len;i++) c[i]=a[len-i-1]-'0';
	for(int i=0;i<len;i++) c[i]*=b;
	for(int i=0;i<len;i++){
		if(c[i]>9){
			c[i+1]+=c[i]/10;
			c[i]%=10;
		}
	}
	while(c[w]) w++;
	string p="";
	for(int i=w-1;i>=0;i--) p+=char(c[i]+'0');
	return p;
}
string plu(string sa,string sb){
	int a[110]={0},b[110]={0},c[110]={0},la=sa.length(),lb=sb.length(),w=max(la,lb);
	for(int i=0;i<la;i++) a[i]=sa[la-i-1]-'0';
	for(int i=0;i<lb;i++) b[i]=sb[lb-i-1]-'0';
	for(int i=0;i<w;i++) c[i]=a[i]+b[i];
	for(int i=0;i<w;i++){
		if(c[i]>9){
			c[i+1]++;
			c[i]-=10;
		}
	}
	if(c[w]) w++;
	string p="";
	for(int i=w-1;i>=0;i--) p+=char(c[i]+'0');
	return p;
}
int main(){
	dp[0][0]="1";
	for(int i=1;i<=100;i++){
		for(int j=1;j<=i;j++){
			if(j==1||i==j) dp[i][j]="1";
			else dp[i][j]=plu(pro(dp[i-1][j],j),dp[i-1][j-1]);
		}
	}
	while(~scanf("%d%d",&n,&m)){
		cout<<dp[n][m];
		putchar('\n');
	}
	return 0;
}
2022/9/16 22:16
加载中...