POJ1157 LITTLE SHOP OF FLOWERS
F个花,V个花瓶,对应F*V种值,后面的花只能选择前面的花所在花瓶的后面的花瓶,求最大值的总和。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #define MAX(a,b) (a) > (b)? (a):(b) 6 #define MIN(a,b) (a) < (b)? (a):(b) 7 #define mem(a) memset(a,0,sizeof(a)) 8 #define INF 1000000007 9 #define MAXN 105 10 using namespace std; 11 12 int DP[MAXN][MAXN]; 13 14 int main() 15 { 16 int F,V; 17 while(~scanf("%d%d",&F,&V)) 18 { 19 int i,j; 20 mem(DP[0]); 21 for(i=1;i<=F;i++) 22 { 23 DP[i][0] = -INF; 24 for(j=1;j<=V;j++) 25 { 26 scanf("%d",&DP[i][j]); 27 DP[i][j]=MAX(DP[i][j-1],DP[i][j]+DP[i-1][j-1]); 28 } 29 } 30 printf("%d\n", DP[F][V]); 31 } 32 return 0; 33 }