fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,m;
  5. int mincost(int a[][1000],int i,int j)
  6. {
  7.  
  8. if(i>n-1 || j>m-1){return 0; }
  9.  
  10.  
  11. int first=a[i][j]+mincost(a,i,j+1);
  12. int second=a[i][j]+mincost(a,i+1,j);
  13. return min(first,second);
  14.  
  15. }
  16.  
  17.  
  18. int main() {
  19.  
  20. cin>>n>>m;
  21. int a[1000][1000];
  22. for(int i=0;i<n;i++)
  23. {
  24. for(int j=0;j<m;j++)
  25. {
  26. cin>>a[i][j];
  27. }
  28.  
  29. }
  30.  
  31. cout<<mincost(a,0,0);
  32.  
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 4516KB
stdin
Standard input is empty
stdout
Standard output is empty