cf 621E. Wet Shark and Blocks
神奇,矩阵乘法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的更多相关文章
- 【矩阵乘法优化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 ...
- 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 ...
- 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 ...
- 【38.24%】【codeforces 621E】 Wet Shark and Blocks
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- [cf621E]Wet Shark and Blocks
Description 给定$n$个数和$b$个盒子,放一些数到盒子中,使得盒子不为空.每个盒子中的数是一样的,一个数可以被放到多个盒子中. 从每个盒子中取一个数,组成一个$b$位数,如果这个数$mo ...
- Codeforces 621E Wet Shark and Block【dp + 矩阵快速幂】
题意: 有b个blocks,每个blocks都有n个相同的0~9的数字,如果从第一个block选1,从第二个block选2,那么就构成12,问对于给定的n,b有多少种构成方案使最后模x的余数为k. 分 ...
- Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks
题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...
- 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 ...
- 【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 ...
随机推荐
- java核心-多线程(6)-线程池-ThreadPoolExecutor
1.java多线程编程少不了使用线程池,线程池相关的工具类所在jdk包,java.util.concurrent 2.使用示例 demo1 public class ThreadPoolDemo { ...
- 嵊州普及Day5T1
题意:有n个商店,自家商店的定价不可高于任何一家商店定价,求自家商店最高定价. 思路:拿个变量打擂台即可,不用解释太多. 见代码: #include<iostream> #include& ...
- 1-2SpringBoot项目属性配置
前面我们讲解了SpringBoot HelloWorld实现 今天具体来讲解上那个application.properties项目配置文件 打开是空白 里面可以配置项目,所以配置项目我们 alt+/ ...
- bootstrap上下左右条纹边框悬停表格的使用
懒得找地址:https://jingyan.baidu.com/album/0bc808fc3d88941bd585b94c.html?picindex=1
- Matplotlib 基本概念
章节 Matplotlib 安装 Matplotlib 入门 Matplotlib 基本概念 Matplotlib 图形绘制 Matplotlib 多个图形 Matplotlib 其他类型图形 Mat ...
- Maven是什么,如何使用Maven
一.简单的小问题? 1.1.假如你正在Eclipse下开发两个Java项目,姑且把它们称为A.B,其中A项目中的一些功能依赖于B项目中的某些类,那么如何维系这种依赖关系的呢? 很简单,这不就是跟我们之 ...
- P1076 Wifi密码
P1076 Wifi密码 转跳点:
- C++面试常见问题——16函数模板的使用
函数模板的使用 函数模板在使用之前必须在外部对函数模板进行初始化. 函数模板的实例化包含两中 1.隐式实例化: template <class T> //没有: T Fun(T a,T b ...
- java随记 2月16
1.a=a+b 等于 a+=b ,且a+=b隐含强制类型转换 2.^ 表示异或 两个二进制同号为假,异号为真 即 0^0=0,1^1=0,0^1=1 3.三元运算 布尔表达式 ?表达式 ...
- 2013蓝桥杯预赛C/C++本科B组
题目标题: 高斯日记 大数学家高斯有个好习惯:无论如何都要记日记. 他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210 后来人们知道,那个整数就是日期,它表示那一天是高斯 ...