题目描述
【题目描述】组合数的高精度算法(combin.cpp/c/pas)
由于邪狼编写的万进制高精度除法有小小的缺陷,导致修罗王打开最后一道牢门时触发了陷阱,修罗王和邪狼因此落入一个类似于N×M的网格棋盘中,修罗王和邪狼必须要从左下角(1,1)开始逃到右上角(M,N)的安全位置,才可以摆脱狱警的追踪,但是修罗王和邪狼每次只能向上或向右走,试问有多少种不同的走法?
【输入格式】
两个整数M,N。
【输出格式】
一个整数,即路径数。
【输入样例】
2 2
【输出样例】
2
提示
n不超过100000,m不超过10000
烦人的高精度
#include<bits/stdc++.h>
using namespace std;
const int qwq = 1e6 + 10;
map<__int128,__int128> a[qwq];
int n,m;
inline int read() {
int x,f=1;
char ch=getchar();
while(ch<'0'||ch>'9') {
if(ch=='-') {
f=-1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9') {
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
return x*f;
}
inline void print(int x) {
int ot;
while(x) {
ot=x%10;
putchar(ot+'0');
x/=10;
}
return ;
}
int main() {
cin>>n>>m;
a[1][1] = 1;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
if(a[i][j] == a[1][1]){
continue;
}
a[i][j] = a[i-1][j] + a[i][j-1];
}
}
print(a[n][m]);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int qwq = 3000;
long long a[qwq][qwq];
int main() {
int n,m;
cin>>n>>m;
a[1][1] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i][j] == a[1][1]) {
continue;
}
a[i][j]=a[i-1][j]+a[i][j-1];
}
}
cout<<a[n][m];
return 0;
}
一个内存超限30分,一个运行错误40分。我要怎么改啊;我不会写二维数组的高精度,有木有dalao帮一下