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\n", a);
        return;
    }
    LL ans = (C(m + i - 1, m, MOD) * a % MOD + C(m + i - 1, i - 2, MOD) * d % MOD) % MOD;
    printf ("%lld\n", 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

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

时间: 2024-10-13 02:13:23

Problem 2238 Daxia & Wzc's problem 1627 瞬间移动的相关文章

FZU Problem 2238 Daxia &amp; Wzc&#39;s problem

Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得到新数列A(1); 然后让Daxia求出数列A(1)前n项和,得到新数列A(2); 接着让Daxia求出数列A(2)前n项和,得到新数列A(3); 规律题,首先写出 a.a+d.a+2d.a+3d...这个容易写出 下面一行也容易写出:a.2a+d.3a+3d.... 再下一行,确实难写,但是通过上

FOJ有奖月赛-2016年8月 Problem A Daxia &amp; Wzc&#39;s problem(找规律)

Problem A Daxia & Wzc's problem Accept: 42    Submit: 228Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得到新数列A(1); 然后让Daxia求出数列A(

51nod 1627 瞬间移动

题意: 有一个n * m的矩形,一开始从(1, 1)开始,每次能够到达右下方格子的一个格子,求到达(n, m)的方案数. 题解: 很显然最多走min (n - 2, m - 2) + 1步,枚举步数K,答案为 求和 C(n - 2, K - 1) * C(m - 2, K - 1) 代码: #include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e5 + 7; #define L

SPOJ Problem 1688:A Very Easy Problem!

递归题..但是没想到的是..这竟然是传说中的答案提交!!害我错了两遍.. 生成程序.. #include<cstdio> int i,a[6]={1315,73,136,255,1384,16385}; void search(int s){ int t=0,r=s; if (s==1)printf("2(0)"); if (s==2)printf("2"); if (s==3)printf("2+2(0)"); if (s>3

FOJ有奖月赛-2016年8月(daxia专场之过四题方有奖)

6/7 这里简单写个题解,由于源代码无法查看,所以过了的题目的代码就不贴了.... 题A Problem A Daxia & Wzc's problem 题意:略 题解:这个东西显然推公式,最后推得的一个组合数学的公式与第一项和公差有关(具体公式隔太久不记得了,囧).然后注意到这个m只有一千,虽然这个i很大,但是C(a,b)的运算次数显然是由a和b较小的一个决定,所以可以优化到算一个组合数的复杂度是min(m,i). 题B Problem B Daxia & Yayamao's probl

POJ 3468 A Simple Problem with Integers

链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 77302 Accepted: 23788 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two ki

poj 3468 A Simple Problem with Integers(线段树+区间更新+区间求和)

题目链接:id=3468http://">http://poj.org/problem? id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 83959   Accepted: 25989 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. Yo

Problem A: Artificial Intelligence?

Description Physics teachers in high school often think that problems given as text are more demanding than pure computations. After all, the pupils have to read and understand the problem first! So they don't state a problem like ``U=10V, I=5A, P=?"

POJ 3468 A Simple Problem with Integers(线段树)

题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 56005   Accepted: 16903 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with