Luogu1655 小朋友的球 (组合数学,第二类斯特林数,高精)
我bingoyes再高精用STL就饿死,死外边!
string真的爽。。。
斯特林数模板题:\(S(n,m) = S(n-1,m-1)+S(n-1,m)*n\)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG
#ifdef ON_DEBUG
#define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("inn.txt","r",stdin);
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#endif
struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
const int N = 1007;
int a[N], b[N];
string add(string A, string B){
string S;
Fill(a, 0), Fill(b, 0);
int lenA = A.size(), lenB = B.size();
R(i,0,lenA - 1) a[i] = A[lenA - i - 1] ^ '0';
R(i,0,lenB - 1) b[i] = B[lenB - i - 1] ^ '0';
int len = Max(lenA, lenB);
R(i,0,len - 1){
a[i] += b[i];
a[i + 1] += a[i] / 10;
a[i] %= 10;
}
if(a[len]) ++len;
nR(i,len - 1,0) S += a[i] + '0';
return S;
}
string mul(string A, int B){
string S;
int len = A.size();
Fill(a, 0);
R(i,0,len - 1) a[i] = A[len - i - 1] ^ '0';
int res = 0;
R(i,0,len - 1){
a[i] = a[i] * B + res;
res = a[i] / 10;
a[i] = a[i] % 10;
}
while(res){
a[len++] = res % 10;
res /= 10;
}
nR(i,len - 1, 0) S += a[i] + '0';
return S;
}
string f[107][107];
int n, m;
int main(){
//FileOpen();
R(i,1,100)
f[i][1] = "1";
R(i,2,100){
R(j,1,i){
f[i][j] = add(f[i - 1][j - 1], mul(f[i - 1][j], j));
}
}
while(~scanf("%d%d", &n, &m)){
if(n < m)
printf("0\n");
else
cout << f[n][m] << "\n";
}
return 0;
}