P2858 [USACO06FEB]奶牛零食Treats for the Cows

Posted WeiAR

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了P2858 [USACO06FEB]奶牛零食Treats for the Cows相关的知识,希望对你有一定的参考价值。

P2858 [USACO06FEB]奶牛零食Treats for the Cows
区间dp,级像矩阵取数,
f[i][i+l]=max(f[i+1][i+l]+a[i]*(m-l),f[i][i+l-1]+a[i+l]*(m-l));

技术分享
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<ctime>
 7 #include<cstring>
 8 #define inf 2147483647
 9 #define For(i,a,b) for(register int i=a;i<=b;i++)
10 #define p(a) putchar(a)
11 #define g() getchar()
12 //by war
13 //2017.10.19
14 using namespace std;
15 int n,m;
16 int a[2010];
17 int f[2010][2010];
18 int Max;
19 int ans;
20 void in(int &x)
21 {
22     int y=1;
23     char c=g();x=0;
24     while(c<0||c>9)
25     {
26     if(c==-)
27     y=-1;
28     c=g();
29     }
30     while(c<=9&&c>=0)x=x*10+c-0,c=g();
31     x*=y;
32 }
33 void o(int x)
34 {
35     if(x<0)
36     {
37         p(-);
38         x=-x;
39     }
40     if(x>9)o(x/10);
41     p(x%10+0);
42 }
43 int main()
44 {
45          in(m);
46          For(jj,1,m)
47          in(a[jj]);
48          For(i,1,m)
49          f[i][i]=m*a[i];
50        For(l,1,m-1)
51           For(i,1,m-l)
52               f[i][i+l]=max(f[i+1][i+l]+a[i]*(m-l),f[i][i+l-1]+a[i+l]*(m-l));
53      o(f[1][m]);
54      return 0;
55 }
View Code

 



以上是关于P2858 [USACO06FEB]奶牛零食Treats for the Cows的主要内容,如果未能解决你的问题,请参考以下文章

洛谷 P2858 [USACO06FEB]奶牛零食Treats for the Cows

AC日记——[USACO06FEB]奶牛零食Treats for the Cows 洛谷 P2858

洛谷P2858·动态规划[USACO06FEB]奶牛零食Treats for the Cows

[luoguP2858] [USACO06FEB]奶牛零食Treats for the Cows(DP)

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

P2857 [USACO06FEB]稳定奶牛分配Steady Cow Assignment