B. Neural Network country
time limit per test

2 seconds

memory limit per test

256 megabytes

Due to the recent popularity of the Deep learning new countries are starting to look like Neural Networks. That is, the countries are being built deep with many layers, each layer possibly having many cities. They also have one entry, and one exit point.

There are exactly L layers, each having N cities. Let us look at the two adjacent layers L1 and L2. Each city from the layer L1 is connected to each city from the layer L2 with the traveling cost cij for , and each pair of adjacent layers has the same cost in between their cities as any other pair (they just stacked the same layers, as usual). Also, the traveling costs to each city from the layer L2are same for all cities in the L1, that is cij is the same for , and fixed j.

Doctor G. needs to speed up his computations for this country so he asks you to find the number of paths he can take from entry to exit point such that his traveling cost is divisible by given number M.

Input

The first line of input contains N (1 ≤ N ≤ 106), L (2 ≤ L ≤ 105) and M (2 ≤ M ≤ 100), the number of cities in each layer, the number of layers and the number that travelling cost should be divisible by, respectively.

Second, third and fourth line contain N integers each denoting costs 0 ≤ cost ≤ M from entry point to the first layer, costs between adjacent layers as described above, and costs from the last layer to the exit point.

Output

Output a single integer, the number of paths Doctor G. can take which have total cost divisible by M, modulo 109 + 7.

Example
input
2 3 13
4 6
2 1
3 4
output
2
Note

This is a country with 3 layers, each layer having 2 cities. Paths , and  are the only paths having total cost divisible by 13. Notice that input edges for layer cities have the same cost, and that they are same for all layers.

题意:

  给你一个起点,和一个终点

  中间这个图是L层的,每层到每层的每个点都有一条权值为b[i]的有向边

  起点到第一层每个点 也有一条权值为a[i]的有向边,最后一层每个点到终点也有一条权值为c[i]有向边,给出a,b,c,求出路径和能整除M的方案数

#include <bits/stdc++.h>
inline long long read(){long long x=,f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}return x*f;}
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const double pi = acos(-1.0);
const long long INF = 1e18+1LL; const int N = , mod = ; struct Matix {
LL arr[][];
}fi,se,ff; int n,L,M; Matix multi (Matix a, Matix b,int p) {
Matix ans;
memset(ans.arr,,sizeof(ans.arr));
if(p) {
for(int i = ; i < M; i++) {
for(int j = ; j < M; j++) {
for(int k = ; k < M; k++)
ans.arr[(i+j)%M][] += (a.arr[i][k] * b.arr[k][j])%mod,
ans.arr[(i+j)%M][] %= mod;
}
}
}
else {
for(int i = ; i < M; ++i) a.arr[i][] = a.arr[][i];
for(int i = ; i < M; i++) {
for(int j = ; j < M; j++) {
for(int k = ; k < M; k++)
ans.arr[][(i+j)%M] += (a.arr[i][k] * b.arr[k][j])%mod,
ans.arr[][(i+j)%M] %= mod;
}
}
}
return ans;
} Matix pows(Matix an,Matix a,LL x) {
while(x) {
if(x&) an=multi(an,a,);
a=multi(a,a,);
x/=;
}
return an;
}
int ar[N];
int main() {
cin >> n >> L >> M;
for(int i = ; i <= n; ++i) {
int x;
scanf("%d",&x);
fi.arr[x % M][] += ;
}
for(int i = ; i <= n; ++i) {
int x;
scanf("%d",&x);
se.arr[][x % M] += ;
ar[i] = x;
}
fi = pows(fi,se,L-);
memset(ff.arr,,sizeof(ff.arr));
for(int i = ; i <= n; ++i) {
int x;
scanf("%d",&x);
ff.arr[][(x+ar[i]) % M] += ;
}
fi = multi(fi,ff,);
LL ans = fi.arr[][];
printf("%lld\n",((ans)%mod+mod)%mod);
return ;
}

  

Bubble Cup X - Finals [Online Mirror] B. Neural Network country 矩阵快速幂加速转移的更多相关文章

  1. Bubble Cup 12 - Finals Online Mirror, unrated, Div. 1

    Bubble Cup 12 - Finals Online Mirror, unrated, Div. 1 C. Jumping Transformers 我会状压 DP! 用 \(dp[x][y][ ...

  2. Bubble Cup 11 - Finals [Online Mirror, Div. 1]题解 【待补】

    Bubble Cup 11 - Finals [Online Mirror, Div. 1] 一场很好玩的题啊! I. Palindrome Pairs 枚举哪种字符出现奇数次. G. AI robo ...

  3. Codeforces Bubble Cup 8 - Finals [Online Mirror] B. Bribes lca

    题目链接: http://codeforces.com/contest/575/problem/B 题解: 把链u,v拆成u,lca(u,v)和v,lca(u,v)(v,lca(u,v)是倒过来的). ...

  4. Codeforces Bubble Cup 8 - Finals [Online Mirror]H. Bots 数学

    H. Bots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/H Desc ...

  5. Codeforces Bubble Cup 8 - Finals [Online Mirror] D. Tablecity 数学题

    D. Tablecity Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/D ...

  6. Codeforces Bubble Cup 8 - Finals [Online Mirror] F. Bulbo DP

    F. Bulbo Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/F Des ...

  7. Bubble Cup X - Finals [Online Mirror]

    来自FallDream的博客,未经允许,请勿转载,谢谢. 组了个菜鸡队打cf上的ACM比赛 比较快做完了8题但是菜的抠脚罚时巨多,所以最后被顶到了19名(居然没出首页) 自己的号自从上次疯狂掉分就没动 ...

  8. Bubble Cup 12 - Finals [Online Mirror, unrated, Div. 1] E. Product Tuples

    题意略,题解生成函数练习题,1+(q-ai)x卷积即可,线段树优化(类似分治思想) //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pra ...

  9. Bubble Cup 13 - Finals [Online Mirror, unrated, Div. 1] K. Lonely Numbers (数学)

    题意:定义两个数\(a,b\)是朋友,如果:\(gcd(a,b)\),\(\frac{a}{gcd(a,b)}\),\(\frac{b}{gcd(a,b)}\)能构成三角形,现在给你一个正整数\(n\ ...

随机推荐

  1. uva 103 Stacking Boxes(最长上升子序列)

    Description    Stacking Boxes  Background Some concepts in Mathematics and Computer Science are simp ...

  2. hust 1605 - Gene recombination(bfs+字典树)

    1605 - Gene recombination Time Limit: 2s Memory Limit: 64MB Submissions: 264 Solved: 46 DESCRIPTION ...

  3. 10个JavaScript难点--摘抄

    1. 立即执行函数 立即执行函数,即Immediately Invoked Function Expression (IIFE),正如它的名字,就是创建函数的同时立即执行.它没有绑定任何事件,也无需等 ...

  4. “百度杯”CTF比赛 九月场_Test(海洋cms前台getshell)

    题目在i春秋ctf训练营 又是一道cms的通用漏洞的题,直接去百度查看通用漏洞 这里我使用的是以下这个漏洞: 海洋CMS V6.28代码执行0day 按照给出的payload,直接访问url+/sea ...

  5. 记一次安装centos7及gnome桌面

    https://blog.csdn.net/bingbingtea/article/details/79553669

  6. 总结下web开发中基础性的常识

    一,HTML/5 1,浏览器渲染过程 主流浏览器渲染过程叫法有区别,但是主要流程还是相同的.Gecko 将视觉格式化元素组成的树称为“框架树”.每个元素都是一个框架.WebKit 使用的术语是“呈现树 ...

  7. POJ 3368.Frequent values-处理数据+RMQ(ST)

    昨天写的博客删了,占坑失败,还是先把RMQ玩的6一点再去搞后面的东西.废话少说,题解题姐姐_(:з」∠)_      Frequent values Time Limit: 2000MS   Memo ...

  8. (38)C#IIS

    IIS7.5标识介绍(转) http://www.cnblogs.com/zgqys1980/p/3862815.html 应用程序池的标识是运行应用程序池的工作进程所使用的服务帐户名称.默认情况下, ...

  9. Codeforces 895C Square Subsets(状压DP 或 异或线性基)

    题目链接  Square Subsets 这是白书原题啊 先考虑状压DP的做法 $2$到$70$总共$19$个质数,所以考虑状态压缩. 因为数据范围是$70$,那么我们统计出$2$到$70$的每个数的 ...

  10. PyTorch学习笔记之Tensors

    PyTorch Tensors are just like numpy arrays, but they can run on GPU.No built-in notion of computatio ...