标签:
Problem Description
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 6 const int maxn = 21; 7 const int maxm = 1000; 8 const int inf = -101; 9 10 int dp[maxn][maxn]; 11 int data[maxm][maxm]; 12 13 int n,m; 14 15 void calc() 16 { 17 int i,j,k; 18 19 dp[0][1] = 0; 20 dp[1][0] = 0; 21 22 for(i = 1;i <= n;++i) 23 { 24 for(j = 1;j <= m;++j) 25 { 26 int temp = inf; 27 for(k = 1;k < j;++k) 28 { 29 if(j % k == 0) 30 temp = max(temp,dp[i][k]); 31 } 32 temp = max(temp,dp[i-1][j]); 33 temp = max(temp,dp[i][j-1]); 34 35 dp[i][j] = data[i][j] + temp; 36 } 37 } 38 } 39 int main() 40 { 41 int N; 42 int i,j; 43 while(cin >> N) 44 { 45 memset(dp,0,sizeof(dp)); 46 cin >>n>>m; 47 for(i = 1;i <= n;++i) 48 { 49 for(j = 1;j <= m;++j) 50 { 51 cin>>data[i][j]; 52 } 53 } 54 calc(); 55 cout<<dp[n][m]<<endl; 56 } 57 }
标签:
原文地址:http://www.cnblogs.com/sxmcACM/p/4821386.html