BZOJ1652 [Usaco2006 Feb]Treats for the Cows 区间动归

约翰经常给产奶量高的奶牛发特殊津贴,于是很快奶牛们拥有了大笔不知该怎么花的钱.为此,约翰购置了N(1≤N≤2000)份美味的零食来卖给奶牛们.每天约翰售出一份零食.当然约翰希望这些零食全部售出后能得到最大的收益.这些零食有以下这些有趣的特性:

?零食按照1..N编号,它们被排成一列放在一个很长的盒子里.盒子的两端都有开口,约翰每

天可以从盒子的任一端取出最外面的一个.

?与美酒与好吃的奶酪相似,这些零食储存得越久就越好吃.当然,这样约翰就可以把它们卖出更高的价钱.

?每份零食的初始价值不一定相同.约翰进货时,第i份零食的初始价值为Vi(1≤Vi≤1000).

?第i份零食如果在被买进后的第a天出售,则它的售价是vi×a.

Vi的是从盒子顶端往下的第i份零食的初始价值.约翰告诉了你所有零食的初始价值,并希望你能帮他计算一下,在这些零食全被卖出后,他最多能得到多少钱.

思路: 我们按间隔的时间分状态k,分别为1~n天 那么每对间隔为k的l和r。而我们假设l或者r在间隔时间内最后取。那么在这个间隔时间内最后取的时间就是n-k+1(因为除了l~r之外其余的都已经被取过了)

转移方程: f[l][r] = max(f[l-1][r] + (n-k-1) *a[l-1],f[l][r+1] + (n-k-1) *a[r+1])

最后答案:f[1][n]

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define ll long long
using namespace std;
int N,a[2005],f[2005][2005];
int main()
{
    cin >> N;
    for(int i=1;i<=N;i++)
        cin >> a[i];
    for(int k=1;k<=N;k++)
          for(int l=1;l+k-1<=N;l++)
          {
            int r=l+k-1;
            f[l][r]=max(f[l+1][r]+(N-k+1)*a[l],f[l][r-1]+(N-k+1)*a[r]);
          }
    cout << f[1][N] << endl;
    return 0;
}  
时间: 2024-10-29 19:10:45

BZOJ1652 [Usaco2006 Feb]Treats for the Cows 区间动归的相关文章

BZOJ1652 [Usaco2006 Feb]Treats for the Cows

蒟蒻许久没做题了,然后连动规方程都写不出了. 参照iwtwiioi大神,这样表示区间貌似更方便. 令f[i, j]表示i到j还没卖出去,则 f[i, j] = max(f[i + 1, j] + v[i] * T, f[i, j - 1] + v[j] * T) (←这样用推的方式更好想一点..) 1 /************************************************************** 2 Problem: 1652 3 User: rausen 4 L

【记忆化搜索】bzoj1652 [Usaco2006 Feb]Treats for the Cows

跟某NOIP的<矩阵取数游戏>很像. f(i,j)表示从左边取i个,从右边取j个的答案. f[x][y]=max(dp(x-1,y)+a[x]*(x+y),dp(x,y-1)+a[n-y+1]*(x+y)). ans=max{f(i,n-i)}. #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define N 2001 int n,a[N],f[N][

BZOJ 1652: [Usaco2006 Feb]Treats for the Cows

题目 1652: [Usaco2006 Feb]Treats for the Cows Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 234  Solved: 185[Submit][Status] Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ se

BZOJ 1652: [Usaco2006 Feb]Treats for the Cows( dp )

dp( L , R ) = max( dp( L + 1 , R ) + V_L * ( n - R + L ) , dp( L , R - 1 ) + V_R * ( n - R + L ) ) 边界 : dp( i , i ) = V[ i ] * n -------------------------------------------------------------------------------------------- #include<cstdio> #include&l

O - Treats for the Cows 区间DP

FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given period time. The treats are interesting for many reasons

poj 3186 Treats for the Cows (区间dp)

题意:给你一个序列,每次只能从头或为取数,然后乘以这是第几个数,最后加和,是加和最大 思路:假设长度最开始是1,然后依次枚举长度,以及起点,dp[i][j]是又里面的两端点扩出来的(ps:代码不是这么写的) 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=2007; int a[maxn],dp[maxn][maxn]; i

bzoj1652:treats for the cows

1652: [Usaco2006 Feb]Treats for the Cows Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 271  Solved: 209[Submit][Status][Discuss] Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk.

poj-3816 Treats for the Cows 【区间DP】

Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4259   Accepted: 2150 Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per da

O - Treats for the Cows POJ 3186 ( 动态规划+区间 )

O - Treats for the Cows Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3186 Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk.