이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |