多组数据注意要初始化dp数组

#include <bits/stdc++.h>
using namespace std;
int dp[101][101], a[101][101];
int T, R, C;
int main()
{
    cin >> T;
    while (T--)
    {
        memset(dp, 0, sizeof(dp));//保险一点,多组数据的时候初始化dp数组
        cin >> R >> C;
        for (int i = 1; i <= R; i++)
            for (int j = 1; j <= C; j++)
            {
                cin >> a[i][j];
            }
        for (int i = 1; i <= R; i++)
            for (int j = 1; j <= C; j++)
            {
                dp[i][j] = max(dp[i][j - 1] + a[i][j], dp[i - 1][j] + a[i][j]);
            }
        cout << dp[R][C] << endl;
    }
    return 0;
}