标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13809 Accepted Submission(s): 4862
#include<iostream> #include<cstdio> using namespace std; int a[1005][1005]; int dp[1005][1005]; int main() { int t; cin >> t; while(t--) { int n, m; cin >> n >> m; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { scanf("%d", &a[i][j]); } } for(int i = 0; i < m; i++) dp[0][i] = -10000; for(int i = 0; i < n; i++) dp[i][0] = -10000; dp[0][1] = 0; dp[1][0] = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); for(int k = 2; k <= m; k++) { if(j % k == 0) dp[i][j] = max(dp[i][j], dp[i][j / k]); } dp[i][j] += a[i][j]; } } cout << dp[n][m] << endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/lyf-acm/p/5456538.html