题目链接:

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

题目大意:

  已知等差数列A(0)的首项a和公差d,求出数列A(0)前n项和,得到新数列A(1);以此类推,最终求A(m)的第i项mod1000000007

题目思路:

  【动态规划】

  不难推出c[i][j]=c[i-1][j]+c[i][j-1]

  但是i太大不能直接递推,m<=1000不能矩阵快速幂。

  通过推导可以求出c[i][j]=a*C(n+m-1,n-1)+d*C(n+m-1,n-2)

  求模时除改为乘逆元(amod-2)

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 1004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int a,d;
LL aa,bb,cc,dd;
LL mi(LL x,int y)
{
LL sum=;
while(y)
{
if(y&)sum=(sum*x)%mod;
x=(x*x)%mod;
y>>=;
}
return sum;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
while(~scanf("%d",&a))
// while(~scanf("%d",&n))
{
scanf("%d%d%d",&d,&m,&n);
for(i=n,aa=;i<=n+m-;i++)
aa=(aa*i)%mod;
for(i=,bb=;i<=m;i++)
bb=(bb*i)%mod;
bb=mi(bb,mod-);
for(i=n-,cc=;i<=n+m-;i++)
cc=(cc*i)%mod;
for(i=,dd=;i<=m+;i++)
dd=(dd*i)%mod;
dd=mi(dd,mod-);
aa=(aa*bb)%mod;aa=(aa*a)%mod;
cc=(cc*dd)%mod;cc=(cc*d)%mod;
printf("%lld\n",(aa+cc)%mod);
}
return ;
}
/*
// //
*/

【数论】FOJ 2238 Daxia & Wzc's problem的更多相关文章

  1. FZU Problem 2238 Daxia & Wzc's problem

    Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得 ...

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

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...

  3. FZU 2238 Daxia & Wzc's problem

    公式. $a×C_{m + i - 1}^m + d×C_{m + i - 1}^{m + 1}$. 推导过程可以看http://blog.csdn.net/queuelovestack/articl ...

  4. FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)

    Problem A Daxia & Wzc's problem Accept: 42    Submit: 228Time Limit: 1000 mSec    Memory Limit : ...

  5. 【模拟】FOJ 2244 Daxia want to buy house

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2244 题目大意: 每月还款额=贷款本金×[月利率×(1+月利率)^还款月数]÷[(1+月利率)^还款月数-1 ...

  6. 【最短路】FOJ 2243 Daxia like uber

    题目链接: http://acm.fzu.edu.cn/problem.php?pid=2243 题目大意: 给一张N个点M条边的有向图,从s出发,把在x1的人送到y1,在x2的人送到y2用的最短距离 ...

  7. FZU 2240 Daxia & Suneast's problem

    博弈,$SG$函数,规律,线段树. 这个问题套路很明显,先找求出$SG$函数值是多少,然后异或起来,如果是$0$就后手赢,否则先手赢.修改操作和区间查询的话可以用线段树维护一下区间异或和. 数据那么大 ...

  8. 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)

    Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...

  9. 【数论】HDU 4143 A Simple Problem

    题目内容 给出一个正整数\(n\),找到最小的正整数\(x\),使之能找到一个整数\(y\),满足\(y^2=n+x^2\). 输入格式 第一行是数据组数\(T\),每组数据有一个整数\(n\). 输 ...

随机推荐

  1. 10.25 noip模拟试题

    今天题目略水2333 依旧不粘题目了23333 T1 /*数学题 给定n个斜率 求有多少个三元组 保证两两斜率不同 ans=C(n,3)-ΣC(len[i],2)*(n-len[i])-ΣC(len[ ...

  2. 开通博客第一天 (先发一些android(java)常见异常信息

    常见异常: java.lang.AbstractMethodError抽象方法错误.当应用试图调用抽象方法时抛出. java.lang.AssertionError断言错.用来指示一个断言失败的情况. ...

  3. Linux运行C#程序

    首先需要安装mono 安装教程http://www.cnblogs.com/aixunsoft/p/3422099.html 然后 用终端执行C#程序就可以了,mono 程序文件名 可以直接执行win ...

  4. php文件粘贴上传

    <?php header("Access-Control-Allow-Origin:*"); $url = 'http://'.$_SERVER['HTTP_HOST']; ...

  5. VisualStudio2015内置LocalDB

    简直坑爹,我将之前的VS2013的工程迁移到新电脑的VS2015,然后用的本地数据库居然连接报错了,然后我试连了一下本地数据库, 就是Tools-->Connect to Databases-- ...

  6. What is SaaS?

    SaaS, or Software as a Service, describes any cloud service where consumers are able to access softw ...

  7. node http.request请求

    var http = require('http'); var querystring = require('querystring'); var path = '/cricket/getRecord ...

  8. 【POJ2985】【Treap + 并查集】The k-th Largest Group

    Description Newman likes playing with cats. He possesses lots of cats in his home. Because the numbe ...

  9. 升级10.10 Yosemite 后,cocoapods 出现错误(解决方案)

    RSMacBook-Pro:~ RS$ pod search jsonkit /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/li ...

  10. Java学习----方法的覆盖

    方法的覆盖:子类继承父类,子类重写父类的同名方法. 覆盖的原则: 1. 方法的参数必须跟父类保持一致 2. 子类方法的修饰符的范围必须大于等于父类方法同名的修饰符(public > privat ...