【数论】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\). 输 ...
随机推荐
- python 学习笔记(二)两种方式实现第一个python程序
在交互模式下: 如果要让Python打印出指定的文字,可以用print语句,然后把希望打印的文字用单引号或者双引号括起来,但不能混用单引号和双引号: >>> print 'hello ...
- HTML5 文件域+FileReader 分段读取文件(四)
一.分段读取txt文本 HTML: <div class="container"> <div class="panel panel-default&qu ...
- HTML5 文件域+FileReader 读取文件(二)
一.读取文本文件内容,指定字符编码 <div class="container"> <!--文本文件验证--> <input type="f ...
- C#超时处理(转载)
/// <summary> /// 超时处理 /// /// /// </summary> public class TimeoutChecker ...
- jquery选择器的使用方式
1.基本选择器 选择器 描述 返回 示例 代码说明 1 id选择器 根据指定的id匹配元素 单个元素 $("#one").css("background", ...
- cetos 6.3 安装 apache+mysql+php
1.安装 apache 服务器 yum install httpd 启动服务 service httpd start or /etc/init.d/httpd start 2.安装 mysql 数 ...
- 菜鸟必备教程,ajax与xml交互传输数据。
今天,公司让学习ajax,然而我并不会,着急到爆炸,boom~~啥卡拉咔.看着教程一步一步摸索,写出来交互页面,写代码真的好惆怅啊. 额,不说废话,下面是源代码. 首先是ajax的代码,注释真的很重要 ...
- PuTTY + Xming 远程使用 Linux GUI
from http://www.zw1840.com/blog/zw1840/2008/10/putty-xming-linux-gui.html 在家里的PC上用VMWare做了一个Oracle E ...
- 用python选择及显示三级目录,可返回上层目录以及随时跳出。
# -*- coding: utf-8 -*-"""Created on Fri Jul 29 09:43:38 2016 @author: yinggang" ...
- django-orm-standalone
django-orm-standalone script via:https://github.com/masnun/django-orm-standalone/ # Django specific ...