POJ 3186Treats for the Cows (区间DP)

 2023-09-11 阅读 21 评论 0

摘要:详见代码 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 using namespace std; 5 int a[2010]; 6 int dp[2010][2010];//i到j的最大和是多少 7 int main() { 8 // freopen("in.txt","r",stdin); 9 int t; 10 while

详见代码

 1 #include <stdio.h>
 2 #include <algorithm>
 3 #include <string.h>
 4 using namespace std;
 5 int a[2010];
 6 int dp[2010][2010];//i到j的最大和是多少
 7 int main() {
 8 //    freopen("in.txt","r",stdin);
 9     int t;
10     while(~scanf("%d",&t)) {
11         for(int i=1; i<=t; i++) {
12             scanf("%d",&a[i]);
13         }
14         memset(dp,0,sizeof(dp));
15         for(int i=t; i>=1; i--) {//逆序访问,顺序不行
16             for(int j=i; j<=t; j++) {
17                 dp[i][j]=max(dp[i+1][j]+a[i]*(t+i-j),dp[i][j-1]+a[j]*(t+i-j));//状态转移方程
18             }
19         }
20         printf("%d\n",dp[1][t]);
21     }
22     return 0;
23 }
View Code

 

转载于:https://www.cnblogs.com/ITUPC/p/5294076.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/45575.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息