Gym101473I Patches
https://codeforces.com/gym/101473/attachments
环形DP
\(dp[i]\)表示\(1~i\)被处理完最少需要覆盖多长的补丁
用二分找出上一个转移位置
然后枚举序列情况即可
复杂度\(O(n^2log n)\)
#include<cstdio>
#include<iostream>
#include<algorithm>
#define INF 2000000007
#define N 2005
using namespace std;
int n,c,t1,t2,a[N],d[N];
int dp[N];
int main()
{
scanf("%d%d%d%d",&n,&c,&t1,&t2);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
int ans=INF;
for (int t=1;t<=n;t++)
{
for (int i=1;i<=n;i++)
d[i]=((a[i]-a[t])%c+c)%c;
sort(d+1,d+n+1);
dp[0]=0;
for (int i=1;i<=n;i++)
{
dp[i]=dp[lower_bound(d+1,d+n+1,d[i]-t1)-d-1]+t1;
dp[i]=min(dp[i],dp[lower_bound(d+1,d+n+1,d[i]-t2)-d-1]+t2);
}
ans=min(ans,dp[n]);
}
cout << ans << endl;
return 0;
}