动态规划训练20 [Treats for the Cows POJ - 3186 ]
生活随笔
收集整理的這篇文章主要介紹了
动态规划训练20 [Treats for the Cows POJ - 3186 ]
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Treats for the Cows
? POJ - 3186?
簡單的區間DP,就不解釋了。
#include<iostream> #include<cstdio> using namespace std; const int INF=1e9; const int maxn=2005; int n, a[maxn]; int dp[maxn][maxn]; int main() {scanf("%d",&n);for(int i=0;i<n;i++) scanf("%d",a+i);for(int i=0;i<n;i++) dp[i][i]=n*a[i];for(int i=1;i<n;i++) {for(int j=0;j<n-i;j++) {dp[j][j+i]=max(dp[j][j+i-1]+(n-i)*a[j+i],dp[j+1][j+i]+(n-i)*a[j]);}}printf("%d\n",dp[0][n-1]);return 0; }總結
以上是生活随笔為你收集整理的动态规划训练20 [Treats for the Cows POJ - 3186 ]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么连接局域网 连接局域网步骤
- 下一篇: 幻化成风歌词 幻化成风完整版歌词