题目链接:

  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. Bash函数使用

    #!/bin/bash function Fun_Name() { #function here echo "this is a function" } Fun_Name

  2. 将list<对象>转换成DataTable,把DataTable转换成参数传入存储过程实现批量插入数据

    领导让在存储过程中批量添加数据,找出效率最高的,我看到后台代码后,发现可以将list<对象>转换成DataTable,把DataTable转换成参数传入存储过程实现批量插入数据,知道还有其 ...

  3. ASP.NET和支付宝合作开发第三方接口的注意事项

    最近公司和支付宝合作开发第三方接口的项目,这里把过程中需要注意的地方说明一下: 前提:一般来说单个银行不接收个人或私企开通支付接口.因此,和第三方支付公司合作,签订合约开放接口就是通行的做法. 流程: ...

  4. javascript ~~ 符号的使用

    其实是一种利用符号进行的类型转换,转换成数字类型 大概是这样滴: ~~true == 1 ~~false == 0 ~~"" == 0 ~~[] == 0 ~~undefined ...

  5. ashx页面 “检测到有潜在危险的 Request.Form 值”的解决方法(控制单个处理程序不检测html标签)

    如题: 使用web.config的configuration/location节点. 在configuration节点内新建一个location节点,注意这个节点和system.webserver那些 ...

  6. [总结]RTMP流媒体技术零基础学习方法

    本文主要总结一些我在学习RTMP流媒体技术过程中积累的经验.也为后来学习RTMP流媒体技术的人们一个参考.本文力图从简到难,循序渐进的介绍RTMP流媒体技术的方方面面,先从应用说起,逐步深化剖析相关工 ...

  7. Java hashCode 和 equals()

    1 Object中定义的hashCode() public int hashCode() Returns a hash code value for the object. This method i ...

  8. 使用程序往Neo4j导入CSV报错

    今天在用程序向Neo4j导入csv文件时,报以下错误: java.net.ConnectException: Connection refused: connect java.rmi.ConnectE ...

  9. linux 监控系统缓存和cpu

    a=`free |head -n 2 |tail -n 1 |awk '{print $7}'`if [ $a -ge 900000 ];then     sync && echo 1 ...

  10. Day13 SQLAlchemy连表操作和堡垒机

    一.数据库操作 1.创建表.插入数据和一对多查询 #!/usr/bin/env python # -*- coding: utf-8 -*- # Author: wanghuafeng from sq ...