神奇,矩阵乘法23333333333333333

递推式是很简单的(连我这种不会DP的人都写出来了。)

需要求出的是转移矩阵(还是叫系数矩阵的),也是最这个东西用快速幂。

这个东西的i,j大概就表示从i到j的方案数,那么原始的状态肯定是f[0]=1;对应的矩阵也就是[1,0,0,0,0,0,0,,,,,,]

貌似为了方便??!!这个矩阵貌似可以转化成f[i][i]=1的矩阵。。。所以。。(太BT了,,,还是我太垃圾)

还有最后的答案输出,想了想data[?][kk],?是什么也不好,一开始是0位,答案求的也是从0到b位的,所以就data[0][kk]吧。。(简直乱搞)

 #include<bits/stdc++.h>
#define inf 0x7fffffff
#define LL long long
#define N 100005
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
const int mod=1e9+;
int a[];
struct maxtri{
int n;
LL data[][];
maxtri(int tn=)
{
n=tn;
for (int i=; i<n; i++)
for (int j=; j<n; j++)
data[i][j]=;
}
void init()
{
for (int i=; i<n; i++) data[i][i]=;
}
};
maxtri operator *(maxtri a, maxtri b)
{
maxtri c(a.n);
int n=a.n;
for (int i=; i<n; i++)
for (int j=; j<n; j++)
for (int k=; k<n; k++)
c.data[i][j]=(c.data[i][j]+a.data[i][k]*b.data[k][j]%mod)%mod;
return c;
}
maxtri ksm(maxtri a, int b)
{
maxtri t(a.n),ans(a.n);
ans.init(); t=a;
while (b)
{
if (b&) ans=ans*t;
t=t*t;
b>>=;
}
return ans;
}
int main()
{
int n=ra(),b=ra(),kk=ra(),x=ra();
for (int i=; i<=n; i++)
a[ra()]++;
maxtri tmp(x);
for (int i=; i<x; i++)
for (int j=; j<x; j++)
for (int k=; k<; k++)
if ((i*+k)%x==j) tmp.data[i][j]+=a[k];
maxtri ans(x);
ans=ksm(tmp,b);
cout<<ans.data[][kk];
return ;
}

cf 621E. Wet Shark and Blocks的更多相关文章

  1. 【矩阵乘法优化dp】[Codeforces 621E] Wet Shark and Blocks

    http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test 2 seconds ...

  2. CODEFORCEs 621E. Wet Shark and Blocks

    E. Wet Shark and Blocks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks dp+矩阵加速

    题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 se ...

  4. 【38.24%】【codeforces 621E】 Wet Shark and Blocks

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. [cf621E]Wet Shark and Blocks

    Description 给定$n$个数和$b$个盒子,放一些数到盒子中,使得盒子不为空.每个盒子中的数是一样的,一个数可以被放到多个盒子中. 从每个盒子中取一个数,组成一个$b$位数,如果这个数$mo ...

  6. Codeforces 621E Wet Shark and Block【dp + 矩阵快速幂】

    题意: 有b个blocks,每个blocks都有n个相同的0~9的数字,如果从第一个block选1,从第二个block选2,那么就构成12,问对于给定的n,b有多少种构成方案使最后模x的余数为k. 分 ...

  7. Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks

    题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...

  8. cf-A. Wet Shark and Odd and Even(水)

    A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  9. 【CodeForces 621A】Wet Shark and Odd and Even

    题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wan ...

随机推荐

  1. Eclipse启动选择启动空间

    window -->preferences-->General-->Startup and Shutdown -->Workspaces-->勾选Prompt for w ...

  2. NPM概述及使用简介

    什么是 NPM npm之于Node,就像pip之于Python,gem之于Ruby,composer之于PHP. npm是Node官方提供的包管理工具,他已经成了Node包的标准发布平台,用于Node ...

  3. SciPy 教程

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...

  4. HashMap ConcurrentHashMap解读

    前言: 常见的关于HahsMap与ConcurrentHashMap的问题: 数据结构.线程安全.扩容.jdk1.7 HashMap死循环.jdk1.8 HashMap红黑树.容量必须是2的冥次 Ha ...

  5. RIOT笔记

    RIOT笔记 2016-04-25 [资源] 维基 https://github.com/RIOT-OS/RIOT/wiki 代码 https://github.com/RIOT-OS/RIOT 网页 ...

  6. python里的def 方法中->代表什么意思?

    功能注释 函数注释是关于用户定义函数使用的类型的完全可选元数据信息(请参阅PEP 3107和 PEP 484了解更多信息). 注释__annotations__ 作为字典存储在函数的属性中,对函数的任 ...

  7. ubuntu18.04下载yarn

    下载curl sudo apt-get update && sudo apt-get install curl 配置库 curl -sS https://dl.yarnpkg.com/ ...

  8. Vue+Axios+Nigix+SpringCloud前端和后端搭建及其碰到的问题

    一.Axios.Router的安装和使用 1.如何安装Axios和Router 1).进入到工程所在的文件夹,通过cmd指令,进入到window的dos界面 2).输入:npm install axi ...

  9. 吴裕雄--天生自然java开发常用类库学习笔记:属性类Properties

    import java.util.Properties; public class PropertiesDemo01{ public static void main(String args[]){ ...

  10. windows 禁用中文输入法(转)

    源博客地址:http://blog.csdn.net/xie1xiao1jun/article/details/17913967 windows 程序禁用中文输入法方法:1.添加windows头文件及 ...