Terrorists 题解
诈骗题。
对每一天枚举点对,
汗水的奖励,如果你被三维偏序骗进去了的话,写
当然,过分容易观察到的是,转移是固定的,所以可以矩阵加速,而且
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const LL mod = 988244353;
const int MAXM = 105;
struct Man {
string g;
int t, c, l;
};
struct Matrix {
int row, col;
vector< vector<LL> > mat;
inline void resize(int x, int y) {
row = x, col = y;
mat.assign(row, vector<LL>(col, 0));
return;
}
inline Matrix operator * (const Matrix& a) const {
Matrix res;
res.resize(row, a.col);
for (int i = 0; i < res.row; ++i)
for (int j = 0; j < res.col; ++j)
for (int k = 0; k < col; ++k)
res.mat[i][j] = (res.mat[i][j] + mat[i][k] * a.mat[k][j]) % mod;
return res;
}
};
int m, n;
Man man[MAXM];
Matrix vecDP, trans;
LL ans;
inline Matrix Pow(Matrix base, LL expo) {
Matrix res;
res.resize(base.row, base.col);
for (int i = 0; i < res.row; ++i)
res.mat[i][i] = 1;
while (expo) {
if (expo & 1)
res = res * base;
base = base * base;
expo >>= 1;
}
return res;
}
int main() {
#ifndef DEBUG
freopen("terrorists.in", "r", stdin);
freopen("terrorists.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#endif
cin >> m >> n;
for (int i = 0; i < m; ++i)
cin >> man[i].g >> man[i].t >> man[i].c >> man[i].l;
vecDP.resize(1, m);
for (int i = 0; i < m; ++i)
vecDP.mat[0][i] = 1;
trans.resize(m, m);
for (int i = 0; i < m; ++i)
for (int j = 0; j < m; ++j) {
if (man[i].t > man[j].t) continue;
if (man[i].c < man[j].c) continue;
if (man[i].l > man[j].l && man[i].g == "b") continue;
trans.mat[j][i]++;
}
trans = Pow(trans, n);
vecDP = vecDP * trans;
for (int i = 0; i < m; ++i)
ans = (ans + vecDP.mat[0][i]) % mod;
cout << ans;
return 0;
}