/* indicates just touch DP. This is my contact with the 3rd DP problem, just beginning to think is to use DFS+DP, later stack overflow ... Think carefully,
In fact, the problem and the same as the tower, as long as each step to get the optimal sub-structure, the final result must be optimal. The initialization of the topic should be done well, so
Can avoid a lot of trouble * *
#include "iostream"
#include "stdio.h"
#include "algorithm"
#include "string.h"
#include "Cmath"
#include "queue"
#include "Stdlib.h"
#define INF-32766
using namespace Std;
int n,m;
int dp[25][1005];
void Init ()
{
for (int i=0;i<=n;i++) {dp[0][i]=inf;dp[i][0]=inf;}
dp[1][0]=dp[0][1]=0;
}
int max (int x,int y)
{
Return x>y?x:y;
}
int main ()
{
int t;
cin>>t;
while (t--)
{
cin>>n>>m;
int i,j,k;
Init ();
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
cin>>dp[i][j];
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
{
int ans=inf;
for (k=1;k<j;k++)
{
if (j%k==0) Ans=max (Ans,dp[i][k]);
}
Ans=max (Ans,dp[i][j-1]);
Dp[i][j]+=max (Ans,dp[i-1][j]); Optimal sub-structure corresponding to optimal results
}
cout<<dp[n][m]<<endl;
}
return 0;
}
HDU-ACM Steps Fate