1 3 8 9 10 10 10 10 -10 10 10 10 -11 -1 0 2 11 10 -20 -11 -11 10 11 2 10 -10 -10
52
#include<iostream> #include<cstring> #include<cmath> using namespace std; int main(){ int t; cin>>t; while(t--){ int n,m,i,j,k; cin>>n>>m; int f[23][1005],dp[23][1005]; for(i=1;i<=n;i++) for(j=1;j<=m;j++) cin>>f[i][j]; for(i=0;i<=n;i++) dp[i][0]=-999999; for(j=0;j<=m;j++) dp[0][j]=-999999; dp[1][0]=dp[0][1]=0; for(i=1;i<=n;i++) for(j=1;j<=m;j++){ dp[i][j]=max(dp[i-1][j],dp[i][j-1])+f[i][j]; for(k=2;j/k>0;k++) if(j%k==0) dp[i][j]=max(dp[i][j],dp[i][j/k]+f[i][j]); } cout<<dp[n][m]<<endl; } return 0; }
原文地址:http://blog.csdn.net/hyccfy/article/details/42870795