加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Luogu1655 小朋友的球 (组合数学,第二类斯特林数,高精)

发布时间:2020-12-14 05:12:19 所属栏目:大数据 来源:网络整理
导读:我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)

我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,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("nn----------nn")
#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,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("0n");
        else
            cout << f[n][m] << "n";
    }
        
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读