【数论】FOJ 2238 Daxia & Wzc's problem
题目链接:
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的更多相关文章
- FZU Problem 2238 Daxia & Wzc's problem
Daxia在2016年5月期间去瑞士度蜜月,顺便拜访了Wzc,Wzc给他出了一个问题: Wzc给Daxia等差数列A(0),告诉Daxia首项a和公差d; 首先让Daxia求出数列A(0)前n项和,得 ...
- Problem 2238 Daxia & Wzc's problem 1627 瞬间移动
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...
- 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 ...
- FZU 8月有奖月赛A Daxia & Wzc's problem (Lucas)
Problem A Daxia & Wzc's problem Accept: 42 Submit: 228Time Limit: 1000 mSec Memory Limit : ...
- 【模拟】FOJ 2244 Daxia want to buy house
题目链接: http://acm.fzu.edu.cn/problem.php?pid=2244 题目大意: 每月还款额=贷款本金×[月利率×(1+月利率)^还款月数]÷[(1+月利率)^还款月数-1 ...
- 【最短路】FOJ 2243 Daxia like uber
题目链接: http://acm.fzu.edu.cn/problem.php?pid=2243 题目大意: 给一张N个点M条边的有向图,从s出发,把在x1的人送到y1,在x2的人送到y2用的最短距离 ...
- FZU 2240 Daxia & Suneast's problem
博弈,$SG$函数,规律,线段树. 这个问题套路很明显,先找求出$SG$函数值是多少,然后异或起来,如果是$0$就后手赢,否则先手赢.修改操作和区间查询的话可以用线段树维护一下区间异或和. 数据那么大 ...
- 数学--数论--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 ...
- 【数论】HDU 4143 A Simple Problem
题目内容 给出一个正整数\(n\),找到最小的正整数\(x\),使之能找到一个整数\(y\),满足\(y^2=n+x^2\). 输入格式 第一行是数据组数\(T\),每组数据有一个整数\(n\). 输 ...
随机推荐
- 表达式:使用API创建表达式树(2)
一.BlockExpression类:表式一个包含可在其中定义变量的表达式序列的块.是一组表达式,类似于多个委托的 += 后的效果,其返回表达式是最后一个表达式决定.以下是BlockExpressio ...
- java 引用资源-ClassLoader.getResource()方法
如图,eclipse中我的包结构为:,我在 spt.app.MainFrame 中可以通过一下代码段使用资源: public static Object obj = ImageIconProxy.cl ...
- c#中的interface abstract与virtual
interface用来声明接口1.只提供一些方法规约,不提供方法主体 如 public interface IPerson { void getName();//不包含方法主体 }2.方法不能 ...
- Ubuntu系统配置日志/var/log/message
ubuntu系统默认不生成/var/log/messages文件,有时候想查看相关日志就很不方便,于是我们可以设置使系统生成此文件. 1.先安装 apt-get install rsyslog2.用v ...
- Oracle AWR报告指标全解析-11011552
1-5 Top 5 Timed EventsWaits : 该等待事件发生的次数, 对于DB CPU此项不可用Times : 该等待事件消耗的总计时间,单位为秒, 对于DB CPU 而言是前台进程所消 ...
- Linux数据写操作改进
Linux的IO操作中数据的写函数int nwrite = write(int fd,void* buf ,int len)表示向fd文件描述符写入len个字节长度的数据报文,但是这并不能保证真正向内 ...
- 【POJ2155】【二维树状数组】Matrix
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- Poj 3667
这是第一题线段树的区间合并的题: 这类的题用于求连续的最长长度什么的: 这题我看的是一篇比较不错的博客: 我把我的理解注释在代码里了: #include <iostream>#includ ...
- 怎样使CSS3中的animation动画当每滑到一屏时每次都运行
这个得结合js来做的.比如这里有3个层,js判断滚动到当前层位置的时候给其加上一个class即可,而加的这个class就是带css3执行动画的 class <div id="a1&qu ...
- 使用Thinkphp框架开发移动端接口
本文给大家分享的是使用thinkphp框架开发移动端接口的2种方法,一种是开发API,另外一种是实现移动端访问自动切换移动主题模板,从而实现伪app访问,下面我们就来详细看下如何实现吧. 方案一:给 ...