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;
}


【ZJOI2005】沼泽鳄鱼

2015-12-30 11:42:26

BZOJ 1898: [Zjoi2005]Swamp 沼泽鳄鱼

2016-03-21 09:43:50

bzoj 1898 [Zjoi2005]Swamp 沼泽鳄鱼 矩阵乘法

2017-10-28 19:30:43

BZOJ1898: [Zjoi2005]Swamp 沼泽鳄鱼

2017-02-28 20:49:30

bzoj1898: [Zjoi2005]Swamp 沼泽鳄鱼

2017-07-08 21:59:42

【ZJOI2005】bzoj 1898 沼泽鳄鱼

2016-07-19 13:27:28

bzoj 1898: [Zjoi2005]Swamp 沼泽鳄鱼 （矩阵乘法优化DP）

2017-02-28 21:01:45

HYSBZ 1898 Swamp 沼泽鳄鱼（矩阵快速幂）

2017-09-08 23:23:46

【BZOJ1898】[Zjoi2005]Swamp 沼泽鳄鱼【DP】【矩阵乘法】

2016-03-15 17:15:02

[BZOJ1898][Zjoi2005]Swamp 沼泽鳄鱼（dp+矩阵优化）

2017-02-08 20:10:54

不良信息举报

1898: [Zjoi2005]Swamp 沼泽鳄鱼