1 solutions
-
0
C++ :
#include <iostream> #include <string.h> #include <stdio.h> using namespace std; const int N = 105; const int INF = 1<<30; int a[N][N]; int dp[N][N]; bool path[N][N]; void Print(int i,int j) { if(i == 0) return; if(path[i][j]) { Print(i-1,j-1); printf("%d ",j); } else Print(i,j-1); } int main() { int F,V; while(~scanf("%d%d",&F,&V)) { memset(path,0,sizeof(path)); for(int i=1;i<=F;i++) for(int j=1;j<=V;j++) scanf("%d",&a[i][j]); for(int i=1;i<=F;i++) for(int j=0;j<=V;j++) dp[i][j] = -INF; for(int i=1;i<=F;i++) { for(int j=i;j<=V && i <= i + F;j++) { if(dp[i-1][j-1] + a[i][j] <= dp[i][j-1]) dp[i][j] = dp[i][j-1]; else { dp[i][j] = dp[i-1][j-1] + a[i][j]; path[i][j] = 1; } } } printf("%d\n",dp[F][V]); Print(F,V); puts(""); } return 0; }
- 1
Information
- ID
- 18430
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By