Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const int N = 1e3 + 5;
- const int mod = 1e9 + 7;
- const int INF = 1e18;
- int dp[N][N];
- int a[N][N];
- signed main()
- {
- 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] = INF;
- }
- }
- 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];
- continue;
- }
- dp[i][j] = min(dp[i - 1][j] , dp[i][j - 1]) + a[i][j];
- }
- }
- cout << dp[n][m] << endl;
- }
Add Comment
Please, Sign In to add comment