# Codeforces 1322D Reality Show (DP)

### 题目链接

https://codeforces.com/contest/1322/problem/D

### 题解

（最大的难点是读题？读错题看了一天题解没看懂的蒟蒻枯了）

### 代码

#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
#define y1 Lorem_ipsum_dolor
using namespace std;

{
int x = 0,f = 1; char ch = getchar();
for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
return x*f;
}

const int mxN = 2e3;
int c[mxN+3],a[mxN+3],w[mxN+mxN+3];
int f[mxN+mxN+3][mxN+3];
int mx[mxN+mxN+3];
int n,m;

void updmax(int &x,int y) {x = max(x,y);}

int main()
{
for(int i=1; i<=n; i++) c[i] = read();
for(int i=1; i<=n; i++) a[i] = read();
for(int i=1; i<=n+m; i++) w[i] = read();
memset(f,213,sizeof(f));
for(int i=1; i<=n+m; i++) f[i][0] = 0;
for(int i=n; i>=1; i--)
{
for(int k=mx[c[i]]; k>=0; k--)
{
int tmp = k+1,val = -a[i]+w[c[i]];
for(int j=0; tmp; j++,tmp>>=1,val+=w[c[i]+j]*tmp)
{
updmax(mx[c[i]+j],tmp);
updmax(f[c[i]+j][tmp],f[c[i]][k]+val);
}
}
for(int j=1; j<=n+m; j++) {updmax(f[j][0],max(f[j-1][0],f[j-1][1]));}
}
printf("%d\n",f[n+m][0]);
return 0;
}


©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客