超时了一个点,能满吗?
#include<bits/stdc++.h>
using namespace std;
int n,m,a[2005][2005],su[2005][2005],sum=1e9;
int xx(int x){
if(x+1<=m)return x+1;
return 1;
}
int read(){
int x=0,f=1;
char ch;
while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return f*x;
}
int dfs(int wz,int k){int th=1e9;
if(su[wz][k])return su[wz][k];if(wz==n+1)return 0;
th=min(th,dfs(wz+1,xx(k))+a[xx(k)][wz]);
th=min(th,dfs(wz+1,k)+a[k][wz]);
return su[wz][k]=th;
}
int main(){
n=read(),m=read();for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)a[i][j]=read();
for(int i=1;i<=m;i++)sum=min(sum,dfs(1,i));
cout<<sum;
return 0;
}