• Problem 2238 Daxia & Wzc's problem 1627 瞬间移动


    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627

    http://acm.fzu.edu.cn/problem.php?pid=2238

    对应的51NOD这个题,先把n--和没m--

    再套公式

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <assert.h>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    LL quick_pow(LL a, LL b, LL MOD) {  //求解 a^b%MOD的值
        LL base = a % MOD;
        LL ans = 1; //相乘,所以这里是1
        while (b) {
            if (b & 1) {
                ans = (ans * base) % MOD; //如果这里是很大的数据,就要用quick_mul
            }
            base = (base * base) % MOD;    //notice。注意这里,每次的base是自己base倍
            b >>= 1;
        }
        return ans;
    }
    LL C(LL n, LL m, LL MOD) {
        if (n < m) return 0; //防止sb地在循环,在lucas的时候
        if (n == m) return 1;
        LL ans1 = 1;
        LL ans2 = 1;
        LL mx = max(n - m, m); //这个也是必要的。能约就约最大的那个
        LL mi = n - mx;
        for (int i = 1; i <= mi; ++i) {
            ans1 = ans1 * (mx + i) %MOD;
            ans2 = ans2 * i % MOD;
        }
        return (ans1 * quick_pow(ans2, MOD - 2, MOD) % MOD); //这里放到最后进行,不然会很慢
    }
    const int MOD = 1e9 + 7;
    void work() {
        int n, m;
        cin >> n >> m;
        cout << C(n + m - 4, n - 2, MOD) << endl;
    }
    int main() {
    #ifdef local
        freopen("data.txt", "r", stdin);
    //    freopen("data.txt", "w", stdout);
    #endif
        work();
        return 0;
    }
    51NOD
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    LL a, d, m, i;
    const int MOD = 1000000007;
    LL quick_pow (LL a, LL b, LL MOD) {
        //求解 a^b%MOD的值
        LL base = a % MOD;
        LL ans = 1; //相乘,所以这里是1
        while (b) {
            if (b & 1) {
                ans = (ans * base) % MOD; //如果这里是很大的数据,就要用quick_mul
            }
            base = (base * base) % MOD;    //notice
            //注意这里,每次的base是自己base倍
            b >>= 1;
        }
        return ans;
    }
    LL C (LL n, LL m, LL MOD) {
        if (n < m) return 0; //防止sb地在循环,在lucas的时候
        if (n == m) return 1;
        LL ans1 = 1;
        LL ans2 = 1;
        LL mx = max(n - m, m); //这个也是必要的。能约就约最大的那个
        LL mi = n - mx;
        for (int i = 1; i <= mi; ++i) {
            ans1 = ans1 * (mx + i) % MOD;
            ans2 = ans2 * i % MOD;
        }
        return (ans1 * quick_pow(ans2, MOD - 2, MOD) % MOD); //这里放到最后进行,不然会很慢
    }
    LL Lucas (LL n, LL m, LL MOD) {
        LL ans = 1;
        while (n && m && ans) {
            ans = ans * C(n % MOD, m % MOD, MOD) % MOD;
            n /= MOD;
            m /= MOD;
        }
        return ans;
    }
    
    void work () {
        if (i == 1) {
            printf ("%lld
    ", a);
            return;
        }
        LL ans = (C(m + i - 1, m, MOD) * a % MOD + C(m + i - 1, i - 2, MOD) * d % MOD) % MOD;
        printf ("%lld
    ", ans);
        return ;
    }
    int main() {
    #ifdef local
        freopen("data.txt", "r", stdin);
    #endif
        while (scanf("%lld%lld%lld%lld", &a, &d, &m, &i) != EOF) work();
        return 0;
    }
    FZUOJ
  • 相关阅读:
    Nim教程【八】(博客园撰写工具客户端更新)
    图解 MongoDB 地理位置索引的实现原理(转)
    MongoDB学习笔记(索引)(转)
    Hadoop集群WordCount运行详解(转)
    java操作mongodb(连接池)(转)
    面向对象设计七大原则(转)
    Spring中IOC和AOP的详细解释(转)
    java单例模式使用及注意事项
    java.io包的总体框架图(转)
    Java常见异常(Runtime Exception )小结(转)
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6149210.html
Copyright © 2020-2023  润新知