首页 > 其他 > 详细

HDU 2571 命运

时间:2014-01-22 17:27:50      阅读:341      评论:0      收藏:0      [点我收藏+]

题解:简单动态规划

bubuko.com,布布扣
#include <cstdio>
#include <iostream>
using namespace std;
int f[21][1001];

int max(int a,int b){return(a>b?a:b);}

int main()
{
   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",&f[i][j]);
        for(int i=n-1; i; i--)
        f[i][m]+=f[i+1][m];
        for(int j=m-1; j; j--)
        f[n][j]+=f[n][j+1];
        for(int i=n-1;i;i--)
        for(int j=m-1;j;j--)
        {
            int temp;
            temp=max(f[i+1][j],f[i][j+1]);
            for(int k=2; k*j<=m; k++)
            temp=max(temp,f[i][k*j]);
            f[i][j]+=temp;
        }
        printf("%d\n",f[1][1]);   
   } 
   return 0;
}
bubuko.com,布布扣

HDU 2571 命运

原文:http://www.cnblogs.com/forever97/p/3529613.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!