Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define fastio ios_base::sync_with_stdio(0); cin.tie(0)
- const int N = 1e3 + 5;
- int a[N][N] , dp[N][N];
- signed main()
- {
- fastio;
- int n , m;
- cin >> n >> m;
- for(int i = 1; i <= n; i++){
- for(int j = 1; j <= m; j++){
- cin >> a[i][j];
- }
- }
- for(int i = 0; i <= n; i++){
- for(int j = 0; j <= m; j++){
- dp[i][j] = LLONG_MAX;
- }
- }
- for(int i = 1; i <= n; i++){
- for(int j = 1; j <= m; j++){
- if(i == 1 && j == 1)
- dp[i][j] = a[i][j];
- else
- dp[i][j] = min(dp[i - 1][j] , dp[i][j - 1]) + a[i][j];
- }
- }
- cout << dp[n][m];
- /*
- 1 2 1
- 1 9 9
- 9 9 1
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement