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

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. Executor 和Executors

    Java里面线程池的顶级接口是Executor,但是严格意义上讲Executor并不是一个线程池,而只是一个执行线程的工具.真正的线程池接口是ExecutorService. 下面这张图完整描述了线程 ...

  2. Ubuntu 安装php mcrypt

    sudo apt-get install php5-mcrypt libmcrypt4 libmcrypt-dev sudo php5enmod mcrypt sudo /etc/init.d/apa ...

  3. 揭开CSS3媒体查询迷雾(min-width和max-width)

    本文参考MichelleKlann的Media Queries Demystified: Min-Width and Max-Width 媒体查询(media queries)是响应式设计(Respo ...

  4. activiti源码解读之心得整编

    TaskService.completeTask()的执行内幕是啥? activiti采取了command模式,completeTask会被包装成一个CompleteTaskCmd,一个Cmd执行的时 ...

  5. Activiti从当前任务任意回退至已审批任务

    http://www.verydemo.com/demo_c161_i143918.html import java.util.HashMap; import java.util.Iterator; ...

  6. IIS启用SSL

    安全套接字层 (SSL) 是一套提供身份验证.保密性和数据完整性的加密技术.SSL 最常用来在 Web 浏览器和 Web 服务器之间建立安全通信通道.它也可以在客户端应用程序和 Web 服务之间使用. ...

  7. SQLserver数据库基础

    1·控制数据库的服务 运行 cmd 在控制面板输入  net  start   MSSQLserver   (启动数据库服务) 在控制面板输入  net  stop   MSSQLserver   ( ...

  8. IO流02_文件过滤器

    [简述] 在File类的list方法中可以接收一个FilenameFilter参数,通过该参数可以列出只满足要求的文件. FilenameFilter接口里包含了一个accept(File dir, ...

  9. config spec

    config_spec Rules for selecting versions of elements to appear in a view APPLICABILITY Product Comma ...

  10. OpenJudge / Poj 1044 Date bugs C++

    链接地址: Poj:http://poj.org/problem?id=1044 OpenJudge:http://bailian.openjudge.cn/practice/1044/ 题目: 总时 ...