• How do you add? UVA


    题意:

    把K个不超过N的非负整数加起来,使它们的和为N,有多少种方法?

    隔板法。。。不会的可以买一本高中数学知识清单。。。给高中班主任打个广告。。。。

    隔板法分两种。。。一种是不存在空集 = C(n-1,m-1)。。。一种是存在空集 = C(n+m-1, m-1)

    这题就是存在空集的解法。。。因为可以是0

    .只会快速幂写组合数的我瑟瑟发抖。。。赶紧翻了紫书。。。

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #define MOD 1000000
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 200, INF = 0x7fffffff;
    LL C[maxn][maxn];
    void init()
    {
        mem(C, 0);
        for(int i=0; i<maxn; i++)
        {
            C[i][0] = 1;
            for(int j=1; j<=i; j++)
                C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
        }
    }
    int main()
    {
        int n, m;
        init();
        while(cin>> n >> m && n+m)
        {
            printf("%d
    ",C[n+m-1][m-1] % MOD);
    
        }
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    1058 A+B in Hogwarts (20)
    1036. Boys vs Girls (25)
    1035 Password (20)
    1027 Colors in Mars (20)
    1009. Product of Polynomials (25)
    1006. Sign In and Sign Out
    1005 Spell It Right (20)
    1046 Shortest Distance (20)
    ViewPager页面滑动,滑动到最后一页,再往后滑动则执行一个事件
    IIS7.0上传文件限制的解决方法
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9316889.html
Copyright © 2020-2023  润新知