java第二类斯特林数编程代码,Luogu1655 小朋友的球 (组合数学,第二类斯特林数,高精)...

我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;

}

16acae93049305c4a77af2e2ef766edd.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值