zoukankan      html  css  js  c++  java
  • luogu P1655 小朋友的球

    //第二类斯特林数
    //第二类斯特林数适用于解决球不同,盒子相同,不能有空盒的情况
    //我们设f[i][j]表示i个球到j个盒子的方案数
    //边界:f[0][0]=1
    //转移:f[i][j]=f[i-1][j]*j+f[i-1][j-1]

    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>  
    #include <string>  
    #include <cstring>  
    #include <cstdio>  
    using namespace std;  
      
    const int maxn = 1000;  
      
    struct bign{  
        int d[maxn], len;  
      
        void clean() { while(len > 1 && !d[len-1]) len--; }  
      
        bign()          { memset(d, 0, sizeof(d)); len = 1; }  
        bign(int num)   { *this = num; }   
        bign(char* num) { *this = num; }  
        bign operator = (const char* num){  
            memset(d, 0, sizeof(d)); len = strlen(num);  
            for(int i = 0; i < len; i++) d[i] = num[len-1-i] - '0';  
            clean();  
            return *this;  
        }  
        bign operator = (int num){  
            char s[20]; sprintf(s, "%d", num);  
            *this = s;  
            return *this;  
        }  
      
        bign operator + (const bign& b){  
            bign c = *this; int i;  
            for (i = 0; i < b.len; i++){  
                c.d[i] += b.d[i];  
                if (c.d[i] > 9) c.d[i]%=10, c.d[i+1]++;  
            }  
            while (c.d[i] > 9) c.d[i++]%=10, c.d[i]++;  
            c.len = max(len, b.len);  
            if (c.d[i] && c.len <= i) c.len = i+1;  
            return c;  
        }  
        bign operator - (const bign& b){  
            bign c = *this; int i;  
            for (i = 0; i < b.len; i++){  
                c.d[i] -= b.d[i];  
                if (c.d[i] < 0) c.d[i]+=10, c.d[i+1]--;  
            }  
            while (c.d[i] < 0) c.d[i++]+=10, c.d[i]--;  
            c.clean();  
            return c;  
        }  
        bign operator * (const bign& b)const{  
            int i, j; bign c; c.len = len + b.len;   
            for(j = 0; j < b.len; j++) for(i = 0; i < len; i++)   
                c.d[i+j] += d[i] * b.d[j];  
            for(i = 0; i < c.len-1; i++)  
                c.d[i+1] += c.d[i]/10, c.d[i] %= 10;  
            c.clean();  
            return c;  
        }  
        bign operator / (const bign& b){  
            int i, j;  
            bign c = *this, a = 0;  
            for (i = len - 1; i >= 0; i--)  
            {  
                a = a*10 + d[i];  
                for (j = 0; j < 10; j++) if (a < b*(j+1)) break;  
                c.d[i] = j;  
                a = a - b*j;  
            }  
            c.clean();  
            return c;  
        }  
        bign operator % (const bign& b){  
            int i, j;  
            bign a = 0;  
            for (i = len - 1; i >= 0; i--)  
            {  
                a = a*10 + d[i];  
                for (j = 0; j < 10; j++) if (a < b*(j+1)) break;  
                a = a - b*j;  
            }  
            return a;  
        }  
        bign operator += (const bign& b){  
            *this = *this + b;  
            return *this;  
        }  
      
        bool operator <(const bign& b) const{  
            if(len != b.len) return len < b.len;  
            for(int i = len-1; i >= 0; i--)  
                if(d[i] != b.d[i]) return d[i] < b.d[i];  
            return false;  
        }  
        bool operator >(const bign& b) const{return b < *this;}  
        bool operator<=(const bign& b) const{return !(b < *this);}  
        bool operator>=(const bign& b) const{return !(*this < b);}  
        bool operator!=(const bign& b) const{return b < *this || *this < b;}  
        bool operator==(const bign& b) const{return !(b < *this) && !(b > *this);}  
      
        string str() const{  
            char s[maxn]={};  
            for(int i = 0; i < len; i++) s[len-1-i] = d[i]+'0';  
            return s;  
        }  
    }f[110][110];  
      
    istream& operator >> (istream& in, bign& x)  {  
        string s;  
        in >> s;  
        x = s.c_str();  
        return in;  
    }  
      
    ostream& operator << (ostream& out, const bign& x)  {  
        out << x.str();  
        return out;  
    }
    
    int main(){
    	int n,m;
    	f[0][0]=1;
    	for(int i=1;i<=100;i++)
    		for(int j=1;j<=100;j++){
    			f[i][j]=f[i-1][j-1]+f[i-1][j]*j;
    		}
    	while(scanf("%d%d",&n,&m)!=EOF){
    		cout<<f[n][m]<<endl;
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Android自己定义组件系列【1】——自己定义View及ViewGroup
    LeetCode60:Permutation Sequence
    GitHub 优秀的 Android 开源项目
    view变化监听器ViewTreeObserver介绍
    android中ImageView的ScaleType属性
    Android静态图片人脸识别的完整demo(附完整源码)
    理解Android的手势识别
    Android浏览图片,点击放大至全屏效果
    Android中如何实现文件下载
    Android语音识别
  • 原文地址:https://www.cnblogs.com/codetogether/p/13371452.html
Copyright © 2011-2022 走看看