Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #define inf 0x3f3f3f3f
- #define pb push_back
- #define mk make_pair
- #define fi first
- #define se second
- #define ii pair<int, int>
- #define all(x) (x).begin(), (x).end()
- #define N 37
- #define M 10007
- int a[N][N];
- int dp[M][N];
- int k;
- int go(int curr, char prev){
- if(curr>=k)return 0;
- int &ret=dp[curr][prev];
- if(ret!=-1)return ret;
- ret=100000000;
- for(int i=0; i<26; i++){
- ret=min(ret, go(curr+1, i)+a[prev][i]);
- }
- return ret;
- }
- int main(int argc, char const *argv[]){
- ios::sync_with_stdio(false);
- cin >> k;
- memset(dp, -1, sizeof dp);
- for(int i=0; i<26; i++){
- for(int j=0; j<26; j++){
- cin >> a[i][j];
- }
- }
- int ans=100000000;
- for(int i=0; i<26; i++){
- ans=min(ans, go(1, i));
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement