标签:
Description
Input
Output
Sample Input
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
Sample Output
52
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> #include <map> using namespace std; #define FIN freopen("input.txt","r",stdin); #define FOUT freopen("output.txt","w",stdout); #define INF 0x3f3f3f3f #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef long long LL; int dp[1005][1005]; int M[25][1005]; int main() { //FIN int T; scanf("%d",&T); while(T--) { int n,m; scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) { scanf("%d",&M[i][j]); } for(int i=0;i<=n;i++) dp[i][0]=-INF; for(int i=0;i<=m;i++) dp[0][i]=-INF; dp[0][1]=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==(double)j/k) dp[i][j]=max(dp[i][j],dp[i][j/k]); } dp[i][j]+=M[i][j]; } printf("%d\n",dp[n][m]); } }
标签:
原文地址:http://www.cnblogs.com/Hyouka/p/5732852.html