图片素材网站建设,外贸企业网络营销,wordpress redis wp_post,wordpress有多少模版传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a;
给你一天hhh小时#xff0c;初始时间是000#xff0c;每天可以使时间aia_iai或者ai−1a_i-1ai−1#xff0c;问最多可以让多少天的时间在[l,r][l,r][l,r]范围内。
思路#xff1a;
算是个比较简单…传送门
文章目录题意思路题意
给你一天hhh小时初始时间是000每天可以使时间aia_iai或者ai−1a_i-1ai−1问最多可以让多少天的时间在[l,r][l,r][l,r]范围内。
思路
算是个比较简单的dpdpdp了一直想贪心没有转换到dpdpdp的思路如果想到dpdpdp那么这个题估计就直接秒了。 设f[i][j]f[i][j]f[i][j]表示到了第iii天时间modh\bmod hmodh为jjj的情况转移方程也比较明显了f[i][j]max(f[i−1][(j−a[i])modh],f[i−1][(j−a[i]1)modh])(l≤j≤r)f[i][j]max(f[i-1][(j-a[i])\bmod h],f[i-1][(j-a[i]1)\bmod h])(l \le j \le r)f[i][j]max(f[i−1][(j−a[i])modh],f[i−1][(j−a[i]1)modh])(l≤j≤r) 直接n2n^2n2转移就好啦。
// Problem: E. Sleeping Schedule
// Contest: Codeforces - Codeforces Round #627 (Div. 3)
// URL: https://codeforces.com/contest/1324/problem/E
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].ltr[u].r1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N2010,mod1e97,INF0x3f3f3f3f;
const double eps1e-6;int n,h,l,r;
int a[N];
int f[N][N],st[N][N];int check(int now) {return nowlnowr;
} int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);memset(f,-63,sizeof(f));scanf(%d%d%d%d,n,h,l,r);for(int i1;in;i) scanf(%d,a[i]);int ans0;f[0][0]0;for(int i1;in;i) {for(int j0;jh;j) {f[i][j]max(f[i-1][(j-a[i]h)%h],f[i-1][(j-a[i]1h)%h])check(j);ansmax(ans,f[i][j]);}}coutansendl;return 0;
}
/**/