#include <iostream>
#include <cstdio>
#define INF 0x3f3f3f3f
using namespace std;
int dp[12][12];
int ans;
int n, m;
int _sch(int x, int y, int num)
{
if(x == n && y == m)
{
if(num > 0&& num < ans)
return ans = num;
}
if(x < n)
{
_sch(x+1, y, num+dp[x+1][y]);
}
if(y < m)
{
_sch(x,y+1,num+dp[x][y+1]);
}
}
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
cin >> dp[i][j];
}
ans = INF;
_sch(1, 1, dp[1][1]);
if(ans == INF)
{
cout << -1 << endl;
}
else
{
cout << ans << endl;
}
return 0;
}
SDUT 1304 取数字
最新推荐文章于 2020-04-02 12:32:09 发布