https://www.acwing.com/problem/content/1017/
1 #include<iostream> 2 using namespace std; 3 const int N=110; 4 int w[N][N],f[N][N]; 5 int main(void){ 6 int t; 7 cin>>t; 8 while(t--){ 9 int n,m; 10 cin>>n>>m; 11 for(int i=1;i<=n;i++){ 12 for(int j=1;j<=m;j++){ 13 cin>>w[i][j]; 14 } 15 } 16 for(int i=1;i<=n;i++){ 17 for(int j=1;j<=m;j++){ 18 f[i][j]=max(f[i-1][j]+w[i][j],f[i][j-1]+w[i][j]); 19 } 20 } 21 cout<<f[n][m]<<endl; 22 } 23 return 0; 24 }