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;
#define int long long
const int MOD = 1e9+7;
int32_t main(){
int n,k;
cin>>n>>k;
vector<vector<int>> dp(n,vector<int>(k,-1));
vector<vector<string>> arr(n,vector<string>(k));
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++){
cin>>arr[i][j];
}
}
function<int(int,int)> f;f=[&](int node, int flag)->int{
if (node==n-1) return 1ll;
if (dp[node][flag]!=-1) return dp[node][flag];
dp[node][flag]=0;
for (int i = 0; i < k; i++){
bool boolean=false;
for (int j = 0; j+node<n; j++){
if (arr[node+1][i].substr(j,node+1)==arr[node][flag]){
boolean=true;
break;
}
}
if (boolean){
dp[node][flag]+=f(node+1,i);
dp[node][flag]%=MOD;
}
}
return dp[node][flag];
};
int ans = 0;
for (int i = 0; i < k; i++){
ans+=f(0,i);
ans%=MOD;
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |