怎么测都是不过 到底是什么问题?
#include <cstdio>
#include <cstring>
int map[1000][1000], n, m, q, ans=1000000, f[1000][1000]={};
int main(){
scanf("%d", &q);
while(q--){
scanf("%d %d", &n, &m);
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++){
scanf("%d", &map[i][j]);
f[i][j]=100000;
}
f[1][1]=0; f[n][m]=map[n][m];
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++){
if(i+1<=n&&f[i][j]+map[i+1][j]<f[i+1][j]) f[i+1][j]=f[i][j]+map[i+1][j];
if(j+1<=m&&f[i][j]+map[i][j+1]<f[i][j+1]) f[i][j+1]=f[i][j]+map[i][j+1];
}
if(n>1&&f[n-1][m]<ans) ans=f[n-1][m];
if(m>1&&f[n][m-1]<ans) ans=f[n][m-1];
if(n==1&&m==1) ans=0;
printf("%d\n", ans+f[n][m]);
memset(f, 0, sizeof(f)); memset(map, 0, sizeof(map));
ans=1000000;
}
return 0;
}