两种构造的方式都是正确的;

1.

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 60
#define ll long long
using namespace std;
int x;
ll M,n;
struct matrix
{
int len_x;
int len_y;
ll data[maxn][maxn];
void ini()
{
len_x=;
len_y=;
memset(data,,sizeof data);
}
}; matrix mat_big;
ll f[maxn][maxn];
matrix s; matrix mat_mul(matrix mat,matrix t)
{
matrix ans;
ans.ini();
ans.len_x=mat.len_x;
ans.len_y=t.len_y;
for(int i=; i<mat.len_x; i++)
{
for(int j=; j<t.len_y; j++)
{
for(int k=; k<mat.len_y; k++)
{
ans.data[i][j]+=(mat.data[i][k]*t.data[k][j])%M;
ans.data[i][j]%=M;
}
}
}
return ans;
} int main()
{
f[][]=;
for(int i=; i<maxn; i++)
for(int j=; j<=i; j++)
{
f[i][j]=f[i-][j]+f[i-][j-];
}
while(scanf("%lld%d%lld",&n,&x,&M)&&n!=-)
{
mat_big.ini();
mat_big.len_x=x+;
mat_big.len_y=x+;
for(int i=; i<=x; i++)
for(int j=; j<=i; j++)
{
mat_big.data[i][j]=x*f[i][j];
if(mat_big.data[i][j]>M)mat_big.data[i][j]%=M;
}
// for(int i=0; i<=x; i++)
// mat_big.data[x+1][i]=mat_big.data[x][i];
mat_big.data[x+][x+]=;
mat_big.data[x+][x]=;
s.ini();
s.len_y=;
s.len_x=x+;
s.data[][]=;
s.data[x+][]=;
// for(int i=0;i<=x+1;i++)
// s.data[i][0]=1;
matrix ret;
ret.ini();
ret.len_x=x+;
ret.len_y=x+;
for(int i=; i<ret.len_x; i++)
ret.data[i][i]=;
n++;
while(n)
{
if(n&)ret=mat_mul(ret,mat_big);
n>>=;
mat_big=mat_mul(mat_big,mat_big);
}
matrix ans=mat_mul(ret,s);
printf("%lld\n",ans.data[x+][]);
}
return ;
}

2.

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 60
#define ll long long
using namespace std;
int x;
ll M,n;
struct matrix
{
int len_x;
int len_y;
ll data[maxn][maxn];
void ini()
{
len_x=;
len_y=;
memset(data,,sizeof data);
}
}; matrix mat_big;
ll f[maxn][maxn];
matrix s; matrix mat_mul(matrix mat,matrix t)
{
matrix ans;
ans.ini();
ans.len_x=mat.len_x;
ans.len_y=t.len_y;
for(int i=; i<mat.len_x; i++)
{
for(int j=; j<t.len_y; j++)
{
for(int k=; k<mat.len_y; k++)
{
ans.data[i][j]+=(mat.data[i][k]*t.data[k][j])%M;
ans.data[i][j]%=M;
}
}
}
return ans;
} int main()
{
f[][]=;
for(int i=; i<maxn; i++)
for(int j=; j<=i; j++)
{
f[i][j]=f[i-][j]+f[i-][j-];
}
while(scanf("%lld%d%lld",&n,&x,&M)&&n!=-)
{
mat_big.ini();
mat_big.len_x=x+;
mat_big.len_y=x+;
for(int i=; i<=x; i++)
for(int j=; j<=i; j++)
{
mat_big.data[i][j]=x*f[i][j];
if(mat_big.data[i][j]>M)mat_big.data[i][j]%=M;
}
for(int i=; i<=x; i++)
mat_big.data[x+][i]=mat_big.data[x][i];
mat_big.data[x+][x+]=;
// mat_big.data[x+1][x]=1;
s.ini();
s.len_y=;
s.len_x=x+;
s.data[][]=;
s.data[x+][]=;
// for(int i=0;i<=x+1;i++)
// s.data[i][0]=1;
matrix ret;
ret.ini();
ret.len_x=x+;
ret.len_y=x+;
for(int i=; i<ret.len_x; i++)
ret.data[i][i]=;
while(n)
{
if(n&)ret=mat_mul(ret,mat_big);
n>>=;
mat_big=mat_mul(mat_big,mat_big);
}
matrix ans=mat_mul(ret,s);
printf("%lld\n",ans.data[x+][]);
}
return ;
}

hdu 3483 A Very Simple Problem的更多相关文章

  1. hdu 5349 MZL's simple problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5349 MZL's simple problem Description A simple proble ...

  2. HDU 4267 A Simple Problem with Integers 多个树状数组

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  3. 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 ...

  4. HDU 3468:A Simple Problem with Integers(线段树+延迟标记)

    A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...

  5. 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 ( ...

  6. 【HDU 3483】 A Very Simple Problem (二项式展开+矩阵加速)

    A Very Simple Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  7. A simple problem 分类: 哈希 HDU 2015-08-06 08:06 1人阅读 评论(0) 收藏

    A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...

  8. A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. HDU 4267 A Simple Problem with Integers

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

随机推荐

  1. jmap命令

    一.jmap -heap PID using parallel threads in the new generation.  ##新生代采用的是并行线程处理方式 using thread-local ...

  2. HTML5 乱记

    HTML5 的文档类型声明可以触发所有具备标准模式的浏览器的标准模式,包括那些对 HTML5 一无所知的浏览器,也就是说,可以在任何网页中都使用 HTML5 文档类型声明 <!DOCTYPE h ...

  3. asp生成静态HTML(动态读取)

    这样的代码多用于我们没有实现设计生成静态的功能,但又想临时将一些动态页面生成静态的,直接获取动态内容并保存为静态的 复制代码代码如下: <!--#include file="admin ...

  4. HashMap 与HashTable的区别

    我们先看2个类的定义 public class Hashtable extends Dictionary implements Map, Cloneable, java.io.Serializable ...

  5. SQL Server高级内容之表表达式和复习

    1. 表表达式 (1) 将表作为一个源或将查询的一个结果集作为一个源,对源做处理,然后得到一个新的数据源,对其进行查询.  (2)表表达式放在from子句中 (3)派生表,将表的查询得到的结果集作为一 ...

  6. C#之装箱和拆箱

    在实际编码过程中,有时候会出现装箱和拆箱操作.下面就类分别认识一下: 需要注意的是,类型转换和这个是不同的.Convert方法并没有发生装箱和拆箱操作,而是类型转换,包括int.parse等等. 装箱 ...

  7. iBeacon 开发笔记

    iBeacon开发笔记 2015.10.19 airlocate ========= airlocate显示如何使用这个监控范围clbeaconregions. 代码还提供了一个例子,你如何能校准和配 ...

  8. C#构造函数相关主题

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  9. Lisp与JAVA的酷毙结合——abcl

    最近看了一本叫做<黑客与画家>的书,其中对于Lisp语言大加褒奖.自己试着用了一下,虽然确实有反人类之嫌,但是确实是一门不错的语言,New Architect杂志上有一篇介绍ITA软件公司 ...

  10. 腾讯视频嵌入手机端网站demo - 就像微信文章中一样一样的

    页面中的调用如下: <iframe id="video_iframe" class="video_iframe" src="TenVideoPl ...