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 itn long long
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=2003;
string a[N][N];
int dp[N][N];
const int mod=1e9+7;
signed main(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++)cin>>a[i][j];
}
for(int i=1;i<=k;i++)dp[1][i]=1;
for(int i=2;i<=n;i++){
for(int j=1;j<=k;j++){
string x=a[i][j];
for(int p=1;p<=k;p++){
string y=a[i-1][p];
if(x.substr(0,i-1)==y or x.substr(1,i-1)==y){
dp[i][j]+=dp[i-1][p];
dp[i][j]%=mod;
}
}
}
}
int ans=0;
for(int i=1;i<=k;i++){
ans+=dp[n][i];
ans%=mod;
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |