我bingoyes再高精用STL就饿死,死外边!
string真的爽。。。
斯特林数模板题:\(S(n,m) = S(n-1,m-1)+S(n-1,m)*n\)
#include
#include
#include
#include
#include
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,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,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{
templateios& 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,lenA - 1) a[i] = A[lenA - i - 1] ^ '0';
R(i,lenB - 1) b[i] = B[lenB - i - 1] ^ '0';
int len = Max(lenA,lenB);
R(i,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,len - 1) a[i] = A[len - i - 1] ^ '0';
int res = 0;
R(i,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,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,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;
}