题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=171
动态规划
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){
int dp[30][30];
int n,m,i,j,k,t;
while(~scanf("%d%d",&n,&m)){
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
scanf("%d",&dp[i][j]);
dp[i][j]+=max(dp[i-1][j],dp[i][j-1]);
}
printf("%d\n",dp[n][m]);
}
return 0;
}