POJ 3186
题意略。
思路:有一点区间dp的意思。
我令dp[ i ][ j ]表示:区间[1 , i]和区间[j , N]按某种顺序插值排好,所能获得的最大值。
状态转移方程:dp[ i ][ j ] = max(dp[i - 1][ j ] + v[ i ] * (i + N - j + 1) , dp[ i ][ j + 1 ] + v[ j ] * (i + N - j + 1))。
代码如下:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = ;
const int F = 0x3f;
const int INF = 0x3f3f3f3f; int N,v[maxn],dp[maxn][maxn]; int main(){
while(scanf("%d",&N) == ){
for(int i = ;i <= N;++i) scanf("%d",&v[i]);
memset(dp,-,sizeof(dp)); dp[][N + ] = ;
for(int i = ;i <= N;++i){
for(int j = N + ;j >= ;--j){
if(i == && j == N + ) continue;
int part1 = i - >= ? dp[i - ][j] + v[i] * (i + N - j + ) : -;
int part2 = j <= N ? dp[i][j + ] + v[j] * (i + N - j + ) : -;
dp[i][j] = max(part1,part2);
}
}
int ans = ;
for(int i = ;i <= N;++i) ans = max(ans,dp[i][i + ]);
printf("%d\n",ans);
}
return ;
}
POJ 3186的更多相关文章
- (区间dp + 记忆化搜索)Treats for the Cows (POJ 3186)
http://poj.org/problem?id=3186 Description FJ has purchased N (1 <= N <= 2000) yummy treats ...
- Treats for the Cows 区间DP POJ 3186
题目来源:http://poj.org/problem?id=3186 (http://www.fjutacm.com/Problem.jsp?pid=1389) /** 题目意思: 约翰经常给产奶量 ...
- POJ 3186 Treats for the Cows 一个简单DP
DP[i][j]表示现在开头是i物品,结尾是j物品的最大值,最后扫一遍dp[1][1]-dp[n][n]就可得到答案了 稍微想一下,就可以, #include<iostream> #inc ...
- poj 3186 Treats for the Cows(区间dp)
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...
- POJ 3186 Treats for the Cows
简单DP dp[i][j]表示的是i到j这段区间获得的a[i]*(j-i)+... ...+a[j-1]*(n-1)+a[j]*n最大值 那么[i,j]这个区间的最大值肯定是由[i+1,j]与[i,j ...
- POJ 3186 Treats for the Cows (动态规划)
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...
- poj 3186 Treats for the Cows(dp)
Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ...
- POJ 3186 Treats for the Cows ——(DP)
第一眼感觉是贪心,,果断WA.然后又设计了一个两个方向的dp方法,虽然觉得有点不对,但是过了样例,交了一发,还是WA,不知道为什么不对= =,感觉是dp的挺有道理的,,代码如下(WA的): #incl ...
- 【POJ - 3186】Treats for the Cows (区间dp)
Treats for the Cows 先搬中文 Descriptions: 给你n个数字v(1),v(2),...,v(n-1),v(n),每次你可以取出最左端的数字或者取出最右端的数字,一共取n次 ...
随机推荐
- 动态规划_Sumsets_POJ-2229
Farmer John commanded his cows to search . Here are the possible sets of numbers that sum to : ) +++ ...
- 用JSP从数据库中读取图片并显示在网页上
<1>先在mysql下建立如下的table. 并insert图像. mysql.sql文件如下: CREATE TABLE photo ( photo_no int(6) unsigned ...
- 虚IP解决程序连只读服务器故障漂移
目前公司有一套核心交易数据库配置了AlWaysON,SQL 2012版本, 1主4从, 其从库(8,14, 8.15) 这2台只读的从数据库服务器, 后台程序和wms等很多程序,都是直接配置IP连接这 ...
- 【iOS】Xcode 离线文档
Xcode 本身下载太慢…… Apple 官方文档地址:https://developer.apple.com/library/downloads/docset-index.dvtdownloadab ...
- MyBatis框架之关联查询
概述:关联查询主要在<resultMap>元素中,用<association>配置一对一.用<collection> 配置一对多 一.一对一查询 1.使 ...
- bit、byte、kb、mb、g的区别
1Byte=8bit1KB=1024Byte(字节)=8*1024bit1MB=1024KB1GB=1024MB1TB=1024GB bit是计算机数据的最小单元.要么是0,要么是1. byte 关键 ...
- 2019前端面试系列——JS高频手写代码题
实现 new 方法 /* * 1.创建一个空对象 * 2.链接到原型 * 3.绑定this值 * 4.返回新对象 */ // 第一种实现 function createNew() { let obj ...
- WPF:事件委托对于不同界面间通信的应用
界面1内设定点击事件,生成Path用事件传出public partial class TemplateWindow : Window { internal delegate v ...
- Hadoop学习(5)-zookeeper的安装和命令行,java操作
zookeeper是干嘛的呢 Zookeeper的作用1.可以为客户端管理少量的数据kvkey:是以路径的形式表示的,那就意味着,各key之间有父子关系,比如/ 是顶层key用户建的key只能在/ 下 ...
- 如何阅读JDK源码
JDK源码阅读笔记: https://github.com/kangjianwei/LearningJDK 如何阅读源码,是每个程序员需要面临的一项挑战. 为什么需要阅读源码?从实用性的角度来看,主要 ...