我有2行3列的网格。我执行的操作是不更新网格的任何元素,而只是访问它。不知何故,我的网格已经使用随机值进行了更新
int grid[2][3]{{1,3,5},
{2,4,-10}};
int row{sizeof(sizeof(grid)/sizeof(grid[0]))};
int col{sizeof(grid[0])/sizeof(int)};
int dp[3][4]{};
for(auto &y:grid){
for(auto x:y){
cout<<x<<"\t";
}
cout<<endl;
}
for(int i{1};i<=row;i++){
for(int j{1};j<=col;j++){
dp[i][j]=grid[i-1][j-1]+max(dp[i][j-1],dp[i-1][j]);
}
}
cout<<"++++++++++++++++++++++++"<<endl;
for(auto &y:grid){
for(auto x:y){
cout<<x<<"\t";
}
cout<<endl;
}
输出:
1 3 5
2 4 -10
++++++++++++++++++++++++
1 4 8
7 4 3
当我在在线IDE(如cpp.sh)上运行此代码时,我没有遇到问题。但是我正在使用devC ++,也许这是我的IDE而不是代码的一些特定问题。