ThuanPhat
Rating
-
Bài tập
1
Điểm
301
Rating #
-
Điểm #
23324
Giới thiệu
include <bits/stdc++.h>
using namespace std;
define ll long long
define F(i, a, b) for(ll i = a; i <= b; ++i)
define Fo(i, a, b) for(ll i = a; i >= b; --i)
define sz(s) (s).size()
define SIZE 1007
define oo 10000
define fase ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<ll> vti;
ll m, n, a[SIZE][SIZE], dp[SIZE][SIZE];
ll min(ll a, ll b) {
return a > b ? b : a;
}
void getIn() {
cin >> m >> n;
F(i, 1, m) F(j, 1, n) cin >> a[i][j];
F(i, 1, m) dp[i][0] = dp[i][m+1] = oo;
F(i, 1, n) dp[0][i] = dp[n+1][i] = oo;
}
void solve() {
freopen("DUONGDI.INP", "r", stdin);
freopen("DUONGDI.OUT", "w", stdout);
getIn();
F(i, 1, m) {
F(j, 1, n) {
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[m][n];
}
signed main() {
int t = 1;
while(t--) solve();
}