# 1898: [Zjoi2005]Swamp 沼泽鳄鱼

139人阅读 评论(0)

## 1898: [Zjoi2005]Swamp 沼泽鳄鱼

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 984  Solved: 557
[Submit][Status][Discuss]

6 8 1 5 3
0 2
2 1
1 0
0 5
5 1
1 4
4 3
3 5
1
3 0 5 1

2

【样例说明】

## Source

[Submit][Status][Discuss]

f[i][j]:时刻i在j号点的方案数

#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cmath>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int mo = 10000;

int n,m,s,t,k,F,Fish[22][5],posi[22],Ans[55],ans[55];
bool Danger[22][55];

vector <int> v[55];

struct R{
int a[55][55];
R(){memset(a,0,sizeof(a));}
R operator * (const R &b) {
R c;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int l = 0; l < n; l++) {
c.a[i][j] += a[i][l]*b.a[l][j];
c.a[i][j] %= mo;
}
return c;
}
}A,B[13];

R ksm(R now,int y)
{
R ret;
for (int i = 0; i < n; i++)
ret.a[i][i] = 1;
for (; y; y >>= 1) {
if (y&1) ret = ret*now;
now = now*now;
}
return ret;
}

int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif

cin >> n >> m >> s >> t >> k;
while (m--) {
int x,y; scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
cin >> F;
for (int i = 1; i <= F; i++) {
scanf("%d",&Fish[i][0]);
for (int j = 1; j <= Fish[i][0]; j++)
scanf("%d",&Fish[i][j]);
posi[i] = 1;
}
for (int i = 0; i <= 12; i++)
for (int j = 1; j <= F; j++) {
Danger[i][Fish[j][posi[j]]] = 1;
++posi[j];
if (posi[j] > Fish[j][0])
posi[j] = 1;
}

for (int T = 1; T <= 12; T++)
for (int i = 0; i < n; i++)
for (int j = 0; j < v[i].size(); j++) {
int from = v[i][j];
if (Danger[T-1][from] || Danger[T][i]) continue;
B[T].a[from][i] = 1;
}
Ans[s] = 1;
for (int i = 0; i < n; i++)
A.a[i][i] = 1;
for (int T = 1; T <= 12; T++)
A = A*B[T];
A = ksm(A,k/12);
k %= 12;
for (int i = 1; i <= k; i++)
A = A*B[i];

for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
ans[i] += Ans[j]*A.a[j][i];
ans[i] %= mo;
}
cout << ans[t];
return 0;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：183036次
• 积分：8763
• 等级：
• 排名：第2554名
• 原创：733篇
• 转载：1篇
• 译文：0篇
• 评论：16条
文章分类
阅读排行
最新评论