Submission #845248

#TimeUsernameProblemLanguageResultExecution timeMemory
845248vjudge1Trener (COCI20_trener)C++17
55 / 110
2004 ms6648 KiB
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define int long long
using namespace std;

const int inf = 2e18 + 5;
const int N = 5e3 + 5;
const int mod = 1e9 + 7;

int32_t main(){
  //freopen("in.txt","r", stdin);
  int n, k;
  cin>>n>>k;
  vector<vector<string> > a(n, vector<string>(k));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < k; j++){
        cin>>a[i][j];
    }
  }
  vector<vector<int> > dp(n+1, vector<int>(k));
  for(int i = 0; i < k; i++){
    dp[0][i] = 1;
  }

  for(int i = 0; i < n-1; i++){
    for(int j = 0; j < k; j++){
        for(int l = 0; l < k; l++){
            if((a[i][j] == a[i+1][l].substr(0, a[i+1][l].size()-1) || a[i][j] == a[i+1][l].substr(1, a[i+1][l].size()-1))){
                dp[i+1][l] += dp[i][j];
                dp[i+1][l] %= mod;
            }
        }
    }
  }

  int s = 0;
  for(int i = 0; i < k; i++){
    s = (s + dp[n-1][i])%mod;
  }
  cout<<s<<endl;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...