This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define endl '\n'
#define fi first
#define se second
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define CDIV(a,b) (((a)+(b)-(1))/(b))
const ll inf = 1e17 + 5;
const ll mod = 1e9 + 7;
const ll N = 1e3 + 30;
ll mod_(ll a, ll b)
{
if(a >= 0)return a % b;
a += (-a/b + 1) * b;
return a % b;
}
void solve()
{
ll n, k;
cin >> n >> k;
vector<vector<string> >v(n, vector<string>(k));
for(ll i = 0; i < n; ++i)
{
for(ll j = 0; j < k; ++j)
cin >> v[i][j];
}
vector<vector<ll> >dp(n, vector<ll>(k));
for(ll i = k - 1; i >= 0; --i)dp[n - 1][i] = 1;
for(ll i = n - 1; i >= 1; --i)
{
for(ll j = 0; j < k; ++j)
{
for(ll z = 0; z < k; ++z)
{
if(v[i - 1][z] == string{v[i][j].begin(), v[i][j].end() - 1})
{
dp[i - 1][z] += dp[i][j];
if(dp[i - 1][z] >= mod)dp[i - 1][z] %= mod;
}
else if(v[i - 1][z] == string{v[i][j].begin() + 1, v[i][j].end()})
{
dp[i - 1][z] += dp[i][j];
if(dp[i - 1][z] >= mod)dp[i - 1][z] %= mod;
}
}
}
}
ll ans = 0;
for(ll i = 0; i < k; ++i) ans = (ans + dp[0][i]) % mod;
cout << ans << endl;
}
int main()
{
fio;
//ll t; cin >> t; while(t--)
{
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |