【HDU 3483】 A Very Simple Problem (二项式展开+矩阵加速)
A Very Simple Problem
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1022 Accepted Submission(s): 500Problem DescriptionThis is a very simple problem. Given three integers N, x, and M, your task is to calculate out the following value:
InputThere are several test cases. For each case, there is a line with three integers N, x, and M, where 1 ≤ N, M ≤ 2*109, and 1 ≤ x ≤ 50.
The input ends up with three negative numbers, which should not be processed as a case.OutputFor each test case, print a line with an integer indicating the result.Sample Input100 1 100003 4 1000-1 -1 -1Sample Output5050444Source
【分析】
感觉我的思想离正解还是太远太远,根本不会这样想。
首先我们发现x很小,k很大,k达到了10^9,for一遍都不行,这样我们就想到ans可能存在递推式,然后可以用矩阵加速。


转自:http://972169909-qq-com.iteye.com/blog/1863402
太厉害了,我自己都好难再推一次~~
代码如下:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define Maxn 60
#define LL long long LL c[Maxn][Maxn];
LL n,x,M; struct node
{
LL a[Maxn][Maxn];
}t[]; void init()
{
memset(c,,sizeof(c));
for(LL i=;i<=;i++) c[i][]=;
for(LL i=;i<=;i++)
for(LL j=;j<=;j++)
c[i][j]=(c[i-][j-]+c[i-][j])%M;
} void get_un()
{
memset(t[].a,,sizeof(t[].a));
for(LL i=;i<=x+;i++) t[].a[i][i]=%M;
} void mul(LL now,LL y,LL z)
{
for(int i=;i<=x+;i++)
for(int j=;j<=x+;j++)
{
t[].a[i][j]=;
for(LL k=;k<=x+;k++)
t[].a[i][j]=(t[].a[i][j]+t[y].a[i][k]*t[z].a[k][j])%M;
}
t[now]=t[];
} void qpow(LL b)
{
get_un();
while(b)
{
if(b&) mul(,,);
mul(,,);
b>>=;
}
} int main()
{
while()
{
scanf("%lld%lld%lld",&n,&x,&M);
if(n==-&&x==-&&M==-) break;
init();
for(LL i=;i<=x;i++)
{
for(LL j=;j<=i;j++) t[].a[i][j]=(x*c[i][j])%M;
for(LL j=i+;j<=x+;j++) t[].a[i][j]=;
}
for(LL i=;i<x;i++) t[].a[x+][i]=;
t[].a[x+][x]=t[].a[x+][x+]=%M;
// get_un();
qpow(n+);
printf("%lld\n",t[].a[x+][]);
}
return ;
}
[HDU 3483]
2016-09-25 22:07:05
【HDU 3483】 A Very Simple Problem (二项式展开+矩阵加速)的更多相关文章
- 【 CodeForces - 392C】 Yet Another Number Sequence (二项式展开+矩阵加速)
Yet Another Number Sequence Description Everyone knows what the Fibonacci sequence is. This sequence ...
- hdu 3483 A Very Simple Problem
两种构造的方式都是正确的: 1. #include<cstdio> #include<cstring> #include<algorithm> #define ma ...
- hdu 5349 MZL's simple problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5349 MZL's simple problem Description A simple proble ...
- HDU 4267 A Simple Problem with Integers 多个树状数组
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2015 Multi-University Training Contest 5 hdu 5349 MZL's simple problem
MZL's simple problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 3468:A Simple Problem with Integers(线段树+延迟标记)
A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...
- hdu3483之二项式展开+矩阵快速幂
A Very Simple Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- HDU 5564 Clarke and digits 状压dp+矩阵加速
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5564 题意: 求长度在[L,R]范围,并且能整除7的整数的总数. 题解: 考虑最原始的想法: dp[ ...
- hdu_3483A Very Simple Problem(C(m,n)+快速幂矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3483 A Very Simple Problem Time Limit: 4000/2000 MS ( ...
随机推荐
- 转:ORACLEERP开发基础之EBS开发基础
转自:http://blog.itpub.net/8781091/viewspace-1012244/ [内容导航] 第1页:开发工具安装 第2页:增加数据块 第3页:注册表单FORM 第4页:注册请 ...
- Socket.io 0.7 – Sending messages to individual clients
Note that this is just for Socket.io version 0.7, and possibly higher if they don’t change the API a ...
- BFM1
BFM应该描述的是具有某种具体功能的电路.比如说,你的待测电路是一个智能卡,那他的BFM就是读卡器:那你就要根据协议,在BFM中描述出读卡器的具体行为. 写BFM就类似于写testbench了.BFM ...
- §12 循环101-while循环
§12 循环101-while循环 While和for具有一定的可替换性.语法如下: while test body continue终止当次循环,break退出整个循环. 注意while之后要用 ...
- js验证
验证短日期(2007-06-05) function strDateTime(str) { var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1 ...
- display:none和visibility:hidden的区别[]
display:none和visibility:hidden都是把网页上某个元素隐藏起来的功能,但两者有所区别,我发现使用 visibility:hidden属性会使对象不可见,但该对象在网页所占的空 ...
- ionic(一) build你的第一个android apk
1.ionic start myApp tabs >>创建一个app 2.cd myApp >>进入myApp文件 3.ionic platform add andro ...
- SqlServer 由于未在SqlServer的此实例上安装复制组件解决方法
sqlserver2005在复制订阅时出现: “由于未在SqlServer的此实例上安装复制组件,Microsoft SQL server 无法访问这些组件,请参阅SQL Server……” 解决方法 ...
- Java线程间通信-回调的实现方式
Java线程间通信-回调的实现方式 Java线程间通信是非常复杂的问题的.线程间通信问题本质上是如何将与线程相关的变量或者对象传递给别的线程,从而实现交互. 比如举一个简单例子,有一个多线程的 ...
- 利用Highcharts制作web图表学习(一)
前言:最近项目中需要对数据进行汇总和分析得出柱状图或曲线图这样散装点图,经过学习和测试发现Highchart不错,如果大家项目中需要的话,不妨看看有的例子摘自官网 一.先说说HighCharts的 ...
