BZOJ2748 [HAOI2012]音量调节 【动态规划初步】
原来有写过这个题解的吧,应该在20150815常州培训填坑的时候。
具体就看代码吧,挺简单的啦。
# include <stdio.h> int n,maxl,minl,beg; int c[51]; bool pd[51][1010]; int main() { scanf("%d%d%d",&n,&beg,&maxl); for (int i=1;i<=n;++i) scanf("%d",&c[i]); pd[0][beg]=1; for (int i=1;i<=n;++i) for (int j=0;j<=1000;++j) { if(j-c[i]>=minl) pd[i][j]=pd[i][j]||pd[i-1][j-c[i]]; if(j+c[i]<=maxl) pd[i][j]=pd[i][j]||pd[i-1][j+c[i]]; } bool flag=1; for (int i=maxl;i>=0;--i) if(pd[n][i]) { printf("%d\n",i); flag=0; break; } if(flag) printf("-1\n"); return 0; }
2023年4月28日 15:38
Our reporting team intends to publish the Education & Recruitment Update for all age groups and present the true picture of the recent events with the inside coverage. datesheet-timetable.in Our objective would be to cater the requirements of people of all age groups as we intend to publish news. Our team comprises of professional writers & citizen journalists with diverse range of interest in Journalism who are passionate about publishing the Education Updates with transparency in general public interest.