http://acm.hdu.edu.cn/showproblem.php?pid=2571
#include <iostream>
#include <cstdio>
using namespace std;
int map[25][1005];
int n,m;
int maxx[25][1005];
int main()
{
int c;
scanf("%d",&c);
while(c--)
{
scanf("%d%d",&n,&m);
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
maxx[i][j]=-999999999,scanf("%d",&map[i][j]);
}
maxx[1][1]=map[1][1];
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(i-1>=1&&maxx[i][j]<map[i][j]+maxx[i-1][j])
maxx[i][j]=map[i][j]+maxx[i-1][j];
if(j-1>=1&&maxx[i][j]<map[i][j]+maxx[i][j-1])
maxx[i][j]=map[i][j]+maxx[i][j-1];
for(int k=1;k<=j/2;k++)
{
if(j%k==0&&maxx[i][j]<maxx[i][k]+map[i][j])
maxx[i][j]=maxx[i][k]+map[i][j];
}
}
}
printf("%d\n",maxx[n][m]);
}
return 0;
}