标签:pen ace 题目 std line geo set 音量 --
//It is coded by Ning_Mew on 4.17
#include<bits/stdc++.h>
using namespace std;
const int maxn=55,maxl=1000+7;
int n,sl,xl,ans=-1;
int c,dp[maxn][maxl];
int main(){
freopen("changingsounds.in","r",stdin);
freopen("changingsounds.out","w",stdout);
scanf("%d%d%d",&n,&sl,&xl);
memset(dp,-1,sizeof(dp));
scanf("%d",&c);
if(sl+c<=xl)dp[1][sl+c]=1;//,ans=max(ans,sl+c);
if(sl-c>=0)dp[1][sl-c]=1;//,ans=max(ans,sl-c);
for(int i=2;i<=n;i++){
scanf("%d",&c);
//cout<<"---------"<<i<<endl;
for(int j=0;j<=xl;j++){
if(j-c>=0)dp[i][j]=max(dp[i][j],dp[i-1][j-c]);
if(j+c<=xl)dp[i][j]=max(dp[i][j],dp[i-1][j+c]);
if(dp[i][j]==1&&i==n)ans=max(ans,j);
//cout<<j<<‘ ‘<<j-c<<‘ ‘<<j+c<<endl;
}
}
printf("%d\n",ans);
return 0;
}
【题解】 bzoj2748 [HAOI2012]音量调节 (动态规划)
标签:pen ace 题目 std line geo set 音量 --
原文地址:https://www.cnblogs.com/Ning-Mew/p/8868143.html