DFS之四
//sicily 1158. Pick numbers
#include<iostream>
using namespace std;
int m,n,table[20][20],res;
void dfs(int s,int x,int y)
{
s+=table[x][y];
if(x==m&&y==n&&s>0)
{
if(res==-1)
res=s;
else
res=min(res,s);
}
if(x<m)
dfs(s,x+1,y);
if(y<n)
dfs(s,x,y+1);
}
int main()
{
while(cin>>m>>n)
{
for(int i=1;i<=m;++i)
for(int j=1;j<=n;++j)
cin>>table[i][j];
res=-1;
dfs(0,1,1);
cout<<res<<endl;
}
return 0;
}