题解:
DAG最小链覆盖=最长反链
然后DP就可以了
这道题网络流怎么建图???
//网络流怎么建图? #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn=1009; typedef long long Lint; int TT; int n,m; int a[maxn][maxn]; Lint f[maxn][maxn]; Lint mx[maxn][maxn]; int main(){ scanf("%d",&TT); while(TT--){ memset(a,0,sizeof(a)); memset(f,0,sizeof(f)); memset(mx,0,sizeof(mx)); scanf("%d%d",&n,&m); for(int i=n;i>=1;--i){ for(int j=1;j<=m;++j){ scanf("%d",&a[i][j]); } } for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ f[i][j]=mx[i-1][j-1]+a[i][j]; mx[i][j]=max(f[i][j],max(mx[i-1][j],mx[i][j-1])); } } printf("%lld ",mx[n][m]); } return 0; }