zoukankan      html  css  js  c++  java
  • SDNU 1311.Binomial Coeffcients

    Description

    The binomial coefficientis the number of ways of picking k unordered outcomes from n possibilities, also known as a combination or combinatorial number.

           Give n and k, you are required to calculate  mod 10000003.

    Input

    The input contains several test cases. The first line of the input contains one positive integer, c, denoting the number of test cases.

           Each of the following c lines contains two integers, n(0<=n<=1000) and k (0<=k<=n), denoting that you are required to calculatemod 10000003.

    Output

    For each test case, output one line containing mod 10000003.

    Sample Input

    3
    1 1
    10 2
    954 723
    

    Sample Output

    1
    45
    3557658
    

    Source

    Unknown
    思路:我滴娘,这道题我本来想用1245的思路去做的,但是发现连long long也存不下了,只能用数论公式:C(N, M) = C(N-1, M)+C(N-1, M-1);
    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <vector>
    using namespace std;
    #define ll long long
    
    ll n, k, num[1000+8][1000+8];
    ll sum;
    
    void init()
    {
        ll sum = 1;
        num[0][0] = 1;
        for(int i = 0; i<1000+1; i++)
        {
            num[i][0] = num[i][i] = 1;
            for(int j = 1; j<i; j++)
                num[i][j] = (num[i-1][j]+num[i-1][j-1])%10000003;
        }
    }
    
    int main()
    {
        init();
        int t;
        scanf("%d", &t);
        while(t--)
        {
            scanf("%lld%lld", &n, &k);
            printf("%lld
    ", num[n][k]);
        }
        return 0;
    }
  • 相关阅读:
    JAVA中的继承
    各种浏览器设置背景颜色线性渐变的方式
    JavaScript原型链
    JavaScript运算符
    QQ聊天:终结编程语言和编程职业
    virutal dom patch
    关于编辑器和语言的一些启示
    node-webkit 资源
    我的程序,你的生活
    过早优化是万恶之源
  • 原文地址:https://www.cnblogs.com/RootVount/p/11011841.html
Copyright © 2011-2022 走看看