AcWing 1015. 摘花生(y总入门组每日一道水题)

1015. 摘花生

模板dp

AC

# include <bits/stdc++.h>
using namespace std;
int f[200][200];
int main(){
    
    
    int tt;cin>>tt;
    while(tt--){
    
    
        int n, m;
        cin>>n>>m;
        for(int i = 1; i <= n; i++ ){
    
    
            for(int j = 1; j <= m; j ++ ){
    
    
                cin>>f[i][j];
                f[i][j]+=max(f[i-1][j],f[i][j-1]);
            }
        }
        cout<<f[n][m]<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45377553/article/details/113403460
今日推荐