【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 ( ...
随机推荐
- SQLhepler用法
1. 将SQLhepler添加进来,命名空间导进来. using Microsoft.ApplicationBlocks.Data; 2. 做连接类DBconnection: public class ...
- 学会用Reflector调试我们的MVC框架代码
我们知道,现在能调试.net程序通常有两个,第一个是ILSpy,还是一个是Reflector,这两个小反编译软件算是我们研究底层代码中所拥有的一把 锋利小尖刀~~~,比如你看到的ILSpy这样的界面图 ...
- .net中压缩和解压缩的处理
最近在网上查了一下在.net中进行压缩和解压缩的方法,方法有很多,我找到了以下几种: 1.利用.net自带的压缩和解压缩方法GZip 参考代码如下: //======================= ...
- Kettle中通过触发器方式实现数据 增量更新
在使用Kettle进行数据同步的时候, 共有 1.使用时间戳进行数据增量更新 2.使用数据库日志进行数据增量更新 3.使用触发器+快照表 进行数据增量更新 今天要介绍的是第3中方法. 实验的思路是这样 ...
- TCP调试助手
网络开发经常要用到一些TCP&UDP的调试工具,搜集一些备用. 目前总结工具有(不分先后): chrome等自带调试器调试HTTP Fiddler(.NET)和Charles debugger ...
- struts2框架加载配置文件的顺序
struts-default.xml:该文件保存在struts2-core-x.x.x.jar文件中: struts-plugin.xml:该文件保存在 struts2-Xxx-x.x.x.jar等S ...
- PHP学习笔记(七)
<wordpress 50个过滤钩子> 11-20 11.gettext: 过滤wordpress的翻译数据. 在wordpress中,使用__(), _e(), _x(), _ex(), ...
- 在HTML中插入回车换行
在制作EPUB的时候,发现原来收集的html文本根本就没有换行,这个在代码里面是无法忍受的,因为看着比较混乱,全部都是在一行里面,这个就像写作文的时候,你看到的文字全部都是在一行里面显示出来的,根本就 ...
- 洛谷 U3178 zty的冒险之行
U3178 zty的冒险之行 题目提供者mangoyang 题目背景 "妈咪妈咪轰"随着一声巨响,zty传送到了Aluba国,在那里浴血奋战,饱读兵书,风餐露宿,吃喝嫖赌,终于到了 ...
- 高性能、高并发TCP服务器(多线程调用libevent)
from:http://blog.csdn.net/i_am_jojo/article/details/7587838 本文讲述的TCP服务器是模仿memcache中的TCP网络处理框架,其中是基于l ...