6 solutions
-
1
动态规划,来看我的。
#include<bits/stdc++.h> using namespace std; typedef long long LL; //dp[i][j]//i:高度,j:位置 /* dp[i][j] = max(dp[i+1][j],dp[i+1][j]) + w[i][j] */ const int N = 1e3+10; int w[N][N]; //每个点的权值 LL dp[N][N]; //存储每个点及以下的权值和 int main(){ int R; cin>>R; for(int i=1;i<=R;i++){ int j=i; for(int j=1;j<=i;j++){ int c; cin>>c; w[i][j] = c; } } for(int i=R;i>=1;i--){ for(int j=1;j<=i;j++){ if(i==R){ dp[i][j]=w[i][j]; } else{ dp[i][j] = max(dp[i+1][j],dp[i+1][j+1]) + w[i][j]; } } } cout<<dp[1][1]<<endl; return 0; }
Information
- ID
- 87
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 223
- Accepted
- 91
- Uploaded By