HDOJ 2391 Filthy Rich dp动态规划.....so easy......

check the pro:http://acm.hdu.edu.cn/showproblem.php?pid=2391

see the code:

#include<iostream>
#include<string>
#include <cstdio>
#include <cmath>
#include<vector>
#include<algorithm>
#include<sstream>
#include<cstdlib>
using namespace std;
const int maxn=1001;
int va[maxn][maxn];
int dp[maxn][maxn];
int maxx(int a,int b,int c){
	int sum=a>b?a:b;
	sum=sum>c?sum:c;
	return sum;
}
int main()
{
	int t,r,c;
	scanf("%d",&t);
	for(int k=1;k<=t;k++)
	{
		scanf("%d%d",&r,&c);
		memset(va,0,sizeof(va));
		memset(dp,0,sizeof(dp));
		for(int i=1;i<=r;i++)
			for(int j=1;j<=c;j++)
				scanf("%d",&va[i][j]);
		for(int i=1;i<=r;i++)
			for(int j=1;j<=c;j++)
			{
				dp[i][j]=maxx(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])+va[i][j];
			}
		cout<<"Scenario #"<<k<<":"<<endl;			
		cout<<dp[r][c]<<endl;
		cout<<endl;	
	}
	return 0;
}



你可能感兴趣的:(C++,算法,动态规划)