DP 简单题 之 poj 1163
DP简单题。。。
要努力呀,虽说现在时间很紧。。。
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 using namespace std; 7 const int MAX_len = 102; 8 int dp[MAX_len][MAX_len]; 9 int n; 10 11 int Solve() 12 { 13 for (int i=1; i<=n; i++) { 14 for (int j=1; j<=i; j++) { 15 dp[i][j] += max(dp[i-1][j-1], dp[i-1][j]); 16 //cout<<dp[i][j]<<'\t'; 17 } 18 //cout<<endl; 19 } 20 int ans = 0; 21 for (int j=1; j<=n; j++) 22 ans = max(ans, dp[n][j]); 23 return ans; 24 } 25 26 int main() 27 { 28 //freopen("input.txt", "r", stdin); 29 //freopen("output.txt", "w", stdout); 30 scanf("%d", &n); 31 memset(dp, 0, sizeof(dp)); 32 for (int i=1; i<=n; i++) { 33 for (int j=1; j<=i; j++) { 34 scanf("%d", &dp[i][j]); 35 } 36 } 37 printf("%d", Solve()); 38 return 0; 39 }