POJ_3167 Cow Patterns

DP,代码有点小白。。。

#include <stdio.h>
#include
<string.h>
#define N 351
int main()
{
int t, i, j, max;
int a[N][N], f[N][N];
//freopen("data.in", "r", stdin);
scanf("%d", &t);
memset(a,
0, sizeof(a));
for(i = 1; i <= t; i++)
for(j = 1; j <= i; j++)
scanf(
"%d", &a[i][j]);
for(i = 1; i <= t; i++)
{
f[i][
1] = f[i-1][1] + a[i][1];
f[i][i]
= f[i-1][i-1] + a[i][i];
for(j = 2; j < i; j++)
{
if(f[i-1][j-1] > f[i-1][j])
f[i][j]
= f[i-1][j-1] + a[i][j];
else f[i][j] = f[i-1][j] + a[i][j];
}
}
max
= f[t][1];
for(i = 2; i <= t; i++)
{
if(max < f[t][i])
max
= f[t][i];
}
printf(
"%d\n",max);
return 0;
}
posted @ 2011-08-03 11:08  AC_Von  阅读(309)  评论(0编辑  收藏  举报