welleyth

4018. Turtle

Dec 27th, 2020
1,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define mp make_pair
  7. #define pb push_back
  8.  
  9. const int N = 1001;
  10. const int INF = (int)1e18;
  11.  
  12. vector<vector<int> > dp(N,vector<int>(N,INF));
  13.  
  14. signed main()
  15. {
  16.     ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
  17.     //freopen("input.txt","r",stdin);
  18.     //freopen("output.txt","w",stdout);
  19.  
  20.     int n,m;
  21.     cin >> n >> m;
  22.  
  23.     for(int i=1;i<=n;i++)
  24.     {
  25.         for(int j=1;j<=m;j++)
  26.         {
  27.             cin >> dp[i][j];
  28.             if(i == 1 && j == 1)
  29.                 continue;
  30.             dp[i][j] += min(dp[i-1][j],dp[i][j-1]);
  31.         }
  32.     }
  33.  
  34.     cout << dp[n][m];
  35.  
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment