这个题目上周对抗赛题目,搞了我好久 对数学这种不是很敏感

其实都不是自己想出来的,看其他的资料和博客的推导 还是有点难度的,反正我是推不出来

通过二项式定理的化简

有两个博客写得比较好

http://972169909-qq-com.iteye.com/blog/1863402

http://www.cppblog.com/Yuan/archive/2010/08/13/123268.html

反正构造好二项式之后,乘N次,就可以得到结果了,因为右边的式子 初始全部是x。

#include <iostream>
#include <cstring>
#include <cstdio>
#define ll __int64
using namespace std;
const int maxn = ;
ll c[maxn][maxn], a[maxn][maxn], b[maxn][maxn], t[maxn][maxn];
ll N,x,M;
void init()
{
int i, j;
memset(c, , sizeof(c));
for (i = ; i <= x; i++)
{
c[i][] = c[i][i] = ;
for (j = ; j < i; j++)
{
c[i][j] = (c[i-][j] + c[i-][j-]) % M;
}
}
memset(a, , sizeof(a));
for (i = ; i <= x; i++)
{
for (j = ; j <= i; j++)
{
a[i][j] = (c[i][j] * x) % M;
}
}
memcpy(a[x+], a[x], sizeof(a[x]));
a[x+][x+] = ;
memset(b, , sizeof(b));
for (i = ; i <= x+; i++)
{
b[i][i] = ;
}
}
void mul(long long p[maxn][maxn], long long q[maxn][maxn])
{
int i, j, k;
memset(t, , sizeof(t));
for (i = ; i <= x+; i++)
{
for (j = ; j <= x+; j++)
{
for (k = ; k <= x+; k++)
{
t[i][j] = (t[i][j] + p[i][k] * q[k][j]) % M;
}
}
}
memcpy(q, t, sizeof(t));
}
void cal()
{
while (N)
{
if (N & )
{
mul(a, b);
}
mul(a, a);
N >>= ;
}
}
int main()
{
while (scanf("%I64d %I64d %I64d", &N, &x,&M)&& N> && x> &&M>)
{
init();
cal();
printf("%I64d\n", b[x+][]);
}
return ;
}

最新文章

  1. classpath: VS classpath*:
  2. 【BZOJ3036】绿豆蛙的归宿 拓补排序+概率
  3. mvc图片上传到服务器
  4. 利用LruCache为GridView异步加载大量网络图片完整示例
  5. Python for Informatics 第11章 正则表达式一(译)
  6. 简单说一下printf(&quot;%*s%s&quot;,xx,xx,xx);或printf(&quot;%*s\n&quot;,xx,xx);
  7. jsoup 简介
  8. 通过案例对 spark streaming 透彻理解三板斧之一: spark streaming 另类实验
  9. blueImp/jQuery file upload 的正确用法(限制上传大小和文件类型)
  10. SQLLite 可以通过SQL语言来访问的文件型SQL数据库
  11. pip是用国内镜像源
  12. 文字处理控件TX Text Control X10独家揭秘(一):数据源自动处理
  13. Android热修复
  14. IT新人论成长
  15. 简约的单页应用引擎:sonnyJS
  16. 共有19款Java 文件上传组件开源软件
  17. PHP &#39;ext/gd/gd.c&#39; gdImageCrop整数符号错误漏洞
  18. windows下Nginx配置与测试
  19. rabbitmq Clustering Guide--官方
  20. [C++][OpenGL]自己写GUI(0)——介绍

热门文章

  1. Scala 线性化规则和 super 操作
  2. 在ubuntu中使用ipython
  3. LeetCode1029 两地调度(贪心+java自定义排序回顾)
  4. Java之集合
  5. systemctl无法停掉keepalived
  6. 3分钟学会Python 针对Excel操作
  7. 083-PHP的foreach循环
  8. centos下将系统预置yum源更换为阿里云源
  9. ubuntu12.04 安装完XRDP显示空白桌面
  10. 类的始祖Object